home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Include / d3dx9mesh.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-28  |  100.8 KB  |  2,537 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (C) Microsoft Corporation.  All Rights Reserved.
  4. //
  5. //  File:       d3dx9mesh.h
  6. //  Content:    D3DX mesh types and functions
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "d3dx9.h"
  11.  
  12. #ifndef __D3DX9MESH_H__
  13. #define __D3DX9MESH_H__
  14.  
  15. // {7ED943DD-52E8-40b5-A8D8-76685C406330}
  16. DEFINE_GUID(IID_ID3DXBaseMesh, 
  17. 0x7ed943dd, 0x52e8, 0x40b5, 0xa8, 0xd8, 0x76, 0x68, 0x5c, 0x40, 0x63, 0x30);
  18.  
  19. // {4020E5C2-1403-4929-883F-E2E849FAC195}
  20. DEFINE_GUID(IID_ID3DXMesh, 
  21. 0x4020e5c2, 0x1403, 0x4929, 0x88, 0x3f, 0xe2, 0xe8, 0x49, 0xfa, 0xc1, 0x95);
  22.  
  23. // {8875769A-D579-4088-AAEB-534D1AD84E96}
  24. DEFINE_GUID(IID_ID3DXPMesh, 
  25. 0x8875769a, 0xd579, 0x4088, 0xaa, 0xeb, 0x53, 0x4d, 0x1a, 0xd8, 0x4e, 0x96);
  26.  
  27. // {667EA4C7-F1CD-4386-B523-7C0290B83CC5}
  28. DEFINE_GUID(IID_ID3DXSPMesh, 
  29. 0x667ea4c7, 0xf1cd, 0x4386, 0xb5, 0x23, 0x7c, 0x2, 0x90, 0xb8, 0x3c, 0xc5);
  30.  
  31. // {11EAA540-F9A6-4d49-AE6A-E19221F70CC4}
  32. DEFINE_GUID(IID_ID3DXSkinInfo, 
  33. 0x11eaa540, 0xf9a6, 0x4d49, 0xae, 0x6a, 0xe1, 0x92, 0x21, 0xf7, 0xc, 0xc4);
  34.  
  35. // {3CE6CC22-DBF2-44f4-894D-F9C34A337139}
  36. DEFINE_GUID(IID_ID3DXPatchMesh, 
  37. 0x3ce6cc22, 0xdbf2, 0x44f4, 0x89, 0x4d, 0xf9, 0xc3, 0x4a, 0x33, 0x71, 0x39);
  38.  
  39. //patch mesh can be quads or tris
  40. typedef enum _D3DXPATCHMESHTYPE {
  41.     D3DXPATCHMESH_RECT   = 0x001,
  42.     D3DXPATCHMESH_TRI    = 0x002,
  43.     D3DXPATCHMESH_NPATCH = 0x003,
  44.  
  45.     D3DXPATCHMESH_FORCE_DWORD    = 0x7fffffff, /* force 32-bit size enum */
  46. } D3DXPATCHMESHTYPE;
  47.  
  48. // Mesh options - lower 3 bytes only, upper byte used by _D3DXMESHOPT option flags
  49. enum _D3DXMESH {
  50.     D3DXMESH_32BIT                  = 0x001, // If set, then use 32 bit indices, if not set use 16 bit indices.
  51.     D3DXMESH_DONOTCLIP              = 0x002, // Use D3DUSAGE_DONOTCLIP for VB & IB.
  52.     D3DXMESH_POINTS                 = 0x004, // Use D3DUSAGE_POINTS for VB & IB. 
  53.     D3DXMESH_RTPATCHES              = 0x008, // Use D3DUSAGE_RTPATCHES for VB & IB. 
  54.     D3DXMESH_NPATCHES               = 0x4000,// Use D3DUSAGE_NPATCHES for VB & IB. 
  55.     D3DXMESH_VB_SYSTEMMEM           = 0x010, // Use D3DPOOL_SYSTEMMEM for VB. Overrides D3DXMESH_MANAGEDVERTEXBUFFER
  56.     D3DXMESH_VB_MANAGED             = 0x020, // Use D3DPOOL_MANAGED for VB. 
  57.     D3DXMESH_VB_WRITEONLY           = 0x040, // Use D3DUSAGE_WRITEONLY for VB.
  58.     D3DXMESH_VB_DYNAMIC             = 0x080, // Use D3DUSAGE_DYNAMIC for VB.
  59.     D3DXMESH_VB_SOFTWAREPROCESSING = 0x8000, // Use D3DUSAGE_SOFTWAREPROCESSING for VB.
  60.     D3DXMESH_IB_SYSTEMMEM           = 0x100, // Use D3DPOOL_SYSTEMMEM for IB. Overrides D3DXMESH_MANAGEDINDEXBUFFER
  61.     D3DXMESH_IB_MANAGED             = 0x200, // Use D3DPOOL_MANAGED for IB.
  62.     D3DXMESH_IB_WRITEONLY           = 0x400, // Use D3DUSAGE_WRITEONLY for IB.
  63.     D3DXMESH_IB_DYNAMIC             = 0x800, // Use D3DUSAGE_DYNAMIC for IB.
  64.     D3DXMESH_IB_SOFTWAREPROCESSING= 0x10000, // Use D3DUSAGE_SOFTWAREPROCESSING for IB.
  65.  
  66.     D3DXMESH_VB_SHARE               = 0x1000, // Valid for Clone* calls only, forces cloned mesh/pmesh to share vertex buffer
  67.  
  68.     D3DXMESH_USEHWONLY              = 0x2000, // Valid for ID3DXSkinInfo::ConvertToBlendedMesh
  69.  
  70.     // Helper options
  71.     D3DXMESH_SYSTEMMEM              = 0x110, // D3DXMESH_VB_SYSTEMMEM | D3DXMESH_IB_SYSTEMMEM
  72.     D3DXMESH_MANAGED                = 0x220, // D3DXMESH_VB_MANAGED | D3DXMESH_IB_MANAGED
  73.     D3DXMESH_WRITEONLY              = 0x440, // D3DXMESH_VB_WRITEONLY | D3DXMESH_IB_WRITEONLY
  74.     D3DXMESH_DYNAMIC                = 0x880, // D3DXMESH_VB_DYNAMIC | D3DXMESH_IB_DYNAMIC
  75.     D3DXMESH_SOFTWAREPROCESSING   = 0x18000, // D3DXMESH_VB_SOFTWAREPROCESSING | D3DXMESH_IB_SOFTWAREPROCESSING
  76.  
  77. };
  78.  
  79. //patch mesh options
  80. enum _D3DXPATCHMESH {
  81.     D3DXPATCHMESH_DEFAULT = 000,
  82. };
  83. // option field values for specifying min value in D3DXGeneratePMesh and D3DXSimplifyMesh
  84. enum _D3DXMESHSIMP
  85. {
  86.     D3DXMESHSIMP_VERTEX   = 0x1,
  87.     D3DXMESHSIMP_FACE     = 0x2,
  88.  
  89. };
  90.  
  91. typedef enum _D3DXCLEANTYPE {
  92.     D3DXCLEAN_BACKFACING    = 0x00000001,
  93.     D3DXCLEAN_BOWTIES        = 0x00000002,
  94.     
  95.     // Helper options
  96.     D3DXCLEAN_SKINNING        = D3DXCLEAN_BACKFACING,    // Bowtie cleaning modifies geometry and breaks skinning
  97.     D3DXCLEAN_OPTIMIZATION    = D3DXCLEAN_BACKFACING,
  98.     D3DXCLEAN_SIMPLIFICATION= D3DXCLEAN_BACKFACING | D3DXCLEAN_BOWTIES,    
  99. } D3DXCLEANTYPE;
  100.  
  101. enum _MAX_FVF_DECL_SIZE
  102. {
  103.     MAX_FVF_DECL_SIZE = MAXD3DDECLLENGTH + 1 // +1 for END
  104. };
  105.  
  106. typedef struct ID3DXBaseMesh *LPD3DXBASEMESH;
  107. typedef struct ID3DXMesh *LPD3DXMESH;
  108. typedef struct ID3DXPMesh *LPD3DXPMESH;
  109. typedef struct ID3DXSPMesh *LPD3DXSPMESH;
  110. typedef struct ID3DXSkinInfo *LPD3DXSKININFO;
  111. typedef struct ID3DXPatchMesh *LPD3DXPATCHMESH;
  112.  
  113. typedef struct _D3DXATTRIBUTERANGE
  114. {
  115.     DWORD AttribId;
  116.     DWORD FaceStart;
  117.     DWORD FaceCount;
  118.     DWORD VertexStart;
  119.     DWORD VertexCount;
  120. } D3DXATTRIBUTERANGE;
  121.  
  122. typedef D3DXATTRIBUTERANGE* LPD3DXATTRIBUTERANGE;
  123.  
  124. typedef struct _D3DXMATERIAL
  125. {
  126.     D3DMATERIAL9  MatD3D;
  127.     LPSTR         pTextureFilename;
  128. } D3DXMATERIAL;
  129. typedef D3DXMATERIAL *LPD3DXMATERIAL;
  130.  
  131. typedef enum _D3DXEFFECTDEFAULTTYPE
  132. {
  133.     D3DXEDT_STRING = 0x1,       // pValue points to a null terminated ASCII string 
  134.     D3DXEDT_FLOATS = 0x2,       // pValue points to an array of floats - number of floats is NumBytes / sizeof(float)
  135.     D3DXEDT_DWORD  = 0x3,       // pValue points to a DWORD
  136.  
  137.     D3DXEDT_FORCEDWORD = 0x7fffffff
  138. } D3DXEFFECTDEFAULTTYPE;
  139.  
  140. typedef struct _D3DXEFFECTDEFAULT
  141. {
  142.     LPSTR                 pParamName;
  143.     D3DXEFFECTDEFAULTTYPE Type;           // type of the data pointed to by pValue
  144.     DWORD                 NumBytes;       // size in bytes of the data pointed to by pValue
  145.     LPVOID                pValue;         // data for the default of the effect
  146. } D3DXEFFECTDEFAULT, *LPD3DXEFFECTDEFAULT;
  147.  
  148. typedef struct _D3DXEFFECTINSTANCE
  149. {
  150.     LPSTR               pEffectFilename;
  151.     DWORD               NumDefaults;
  152.     LPD3DXEFFECTDEFAULT pDefaults;
  153. } D3DXEFFECTINSTANCE, *LPD3DXEFFECTINSTANCE;
  154.  
  155. typedef struct _D3DXATTRIBUTEWEIGHTS
  156. {
  157.     FLOAT Position;
  158.     FLOAT Boundary;
  159.     FLOAT Normal;
  160.     FLOAT Diffuse;
  161.     FLOAT Specular;
  162.     FLOAT Texcoord[8];
  163.     FLOAT Tangent;
  164.     FLOAT Binormal;
  165. } D3DXATTRIBUTEWEIGHTS, *LPD3DXATTRIBUTEWEIGHTS;
  166.  
  167. enum _D3DXWELDEPSILONSFLAGS
  168. {
  169.     D3DXWELDEPSILONS_WELDALL             = 0x1,  // weld all vertices marked by adjacency as being overlapping
  170.  
  171.     D3DXWELDEPSILONS_WELDPARTIALMATCHES  = 0x2,  // if a given vertex component is within epsilon, modify partial matched 
  172.                                                     // vertices so that both components identical AND if all components "equal"
  173.                                                     // remove one of the vertices
  174.     D3DXWELDEPSILONS_DONOTREMOVEVERTICES = 0x4,  // instructs weld to only allow modifications to vertices and not removal
  175.                                                     // ONLY valid if D3DXWELDEPSILONS_WELDPARTIALMATCHES is set
  176.                                                     // useful to modify vertices to be equal, but not allow vertices to be removed
  177.  
  178.     D3DXWELDEPSILONS_DONOTSPLIT          = 0x8,  // instructs weld to specify the D3DXMESHOPT_DONOTSPLIT flag when doing an Optimize(ATTR_SORT)
  179.                                                     // if this flag is not set, all vertices that are in separate attribute groups
  180.                                                     // will remain split and not welded.  Setting this flag can slow down software vertex processing
  181.  
  182. };
  183.  
  184. typedef struct _D3DXWELDEPSILONS
  185. {
  186.     FLOAT Position;                 // NOTE: This does NOT replace the epsilon in GenerateAdjacency
  187.                                             // in general, it should be the same value or greater than the one passed to GeneratedAdjacency
  188.     FLOAT BlendWeights;
  189.     FLOAT Normal;
  190.     FLOAT PSize;
  191.     FLOAT Specular;
  192.     FLOAT Diffuse;
  193.     FLOAT Texcoord[8];
  194.     FLOAT Tangent;
  195.     FLOAT Binormal;
  196.     FLOAT TessFactor;
  197. } D3DXWELDEPSILONS;
  198.  
  199. typedef D3DXWELDEPSILONS* LPD3DXWELDEPSILONS;
  200.  
  201.  
  202. #undef INTERFACE
  203. #define INTERFACE ID3DXBaseMesh
  204.  
  205. DECLARE_INTERFACE_(ID3DXBaseMesh, IUnknown)
  206. {
  207.     // IUnknown
  208.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  209.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  210.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  211.  
  212.     // ID3DXBaseMesh
  213.     STDMETHOD(DrawSubset)(THIS_ DWORD AttribId) PURE;
  214.     STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE;
  215.     STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE;
  216.     STDMETHOD_(DWORD, GetFVF)(THIS) PURE;
  217.     STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  218.     STDMETHOD_(DWORD, GetNumBytesPerVertex)(THIS) PURE;
  219.     STDMETHOD_(DWORD, GetOptions)(THIS) PURE;
  220.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
  221.     STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, 
  222.                 DWORD FVF, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXMESH* ppCloneMesh) PURE;
  223.     STDMETHOD(CloneMesh)(THIS_ DWORD Options, 
  224.                 CONST D3DVERTEXELEMENT9 *pDeclaration, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXMESH* ppCloneMesh) PURE;
  225.     STDMETHOD(GetVertexBuffer)(THIS_ LPDIRECT3DVERTEXBUFFER9* ppVB) PURE;
  226.     STDMETHOD(GetIndexBuffer)(THIS_ LPDIRECT3DINDEXBUFFER9* ppIB) PURE;
  227.     STDMETHOD(LockVertexBuffer)(THIS_ DWORD Flags, LPVOID *ppData) PURE;
  228.     STDMETHOD(UnlockVertexBuffer)(THIS) PURE;
  229.     STDMETHOD(LockIndexBuffer)(THIS_ DWORD Flags, LPVOID *ppData) PURE;
  230.     STDMETHOD(UnlockIndexBuffer)(THIS) PURE;
  231.     STDMETHOD(GetAttributeTable)(
  232.                 THIS_ D3DXATTRIBUTERANGE *pAttribTable, DWORD* pAttribTableSize) PURE;
  233.  
  234.     STDMETHOD(ConvertPointRepsToAdjacency)(THIS_ CONST DWORD* pPRep, DWORD* pAdjacency) PURE;
  235.     STDMETHOD(ConvertAdjacencyToPointReps)(THIS_ CONST DWORD* pAdjacency, DWORD* pPRep) PURE;
  236.     STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Epsilon, DWORD* pAdjacency) PURE;
  237.  
  238.     STDMETHOD(UpdateSemantics)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  239. };
  240.  
  241.  
  242. #undef INTERFACE
  243. #define INTERFACE ID3DXMesh
  244.  
  245. DECLARE_INTERFACE_(ID3DXMesh, ID3DXBaseMesh)
  246. {
  247.     // IUnknown
  248.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  249.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  250.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  251.  
  252.     // ID3DXBaseMesh
  253.     STDMETHOD(DrawSubset)(THIS_ DWORD AttribId) PURE;
  254.     STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE;
  255.     STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE;
  256.     STDMETHOD_(DWORD, GetFVF)(THIS) PURE;
  257.     STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  258.     STDMETHOD_(DWORD, GetNumBytesPerVertex)(THIS) PURE;
  259.     STDMETHOD_(DWORD, GetOptions)(THIS) PURE;
  260.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
  261.     STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, 
  262.                 DWORD FVF, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXMESH* ppCloneMesh) PURE;
  263.     STDMETHOD(CloneMesh)(THIS_ DWORD Options, 
  264.                 CONST D3DVERTEXELEMENT9 *pDeclaration, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXMESH* ppCloneMesh) PURE;
  265.     STDMETHOD(GetVertexBuffer)(THIS_ LPDIRECT3DVERTEXBUFFER9* ppVB) PURE;
  266.     STDMETHOD(GetIndexBuffer)(THIS_ LPDIRECT3DINDEXBUFFER9* ppIB) PURE;
  267.     STDMETHOD(LockVertexBuffer)(THIS_ DWORD Flags, LPVOID *ppData) PURE;
  268.     STDMETHOD(UnlockVertexBuffer)(THIS) PURE;
  269.     STDMETHOD(LockIndexBuffer)(THIS_ DWORD Flags, LPVOID *ppData) PURE;
  270.     STDMETHOD(UnlockIndexBuffer)(THIS) PURE;
  271.     STDMETHOD(GetAttributeTable)(
  272.                 THIS_ D3DXATTRIBUTERANGE *pAttribTable, DWORD* pAttribTableSize) PURE;
  273.  
  274.     STDMETHOD(ConvertPointRepsToAdjacency)(THIS_ CONST DWORD* pPRep, DWORD* pAdjacency) PURE;
  275.     STDMETHOD(ConvertAdjacencyToPointReps)(THIS_ CONST DWORD* pAdjacency, DWORD* pPRep) PURE;
  276.     STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Epsilon, DWORD* pAdjacency) PURE;
  277.  
  278.     STDMETHOD(UpdateSemantics)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  279.  
  280.     // ID3DXMesh
  281.     STDMETHOD(LockAttributeBuffer)(THIS_ DWORD Flags, DWORD** ppData) PURE;
  282.     STDMETHOD(UnlockAttributeBuffer)(THIS) PURE;
  283.     STDMETHOD(Optimize)(THIS_ DWORD Flags, CONST DWORD* pAdjacencyIn, DWORD* pAdjacencyOut, 
  284.                      DWORD* pFaceRemap, LPD3DXBUFFER *ppVertexRemap,  
  285.                      LPD3DXMESH* ppOptMesh) PURE;
  286.     STDMETHOD(OptimizeInplace)(THIS_ DWORD Flags, CONST DWORD* pAdjacencyIn, DWORD* pAdjacencyOut, 
  287.                      DWORD* pFaceRemap, LPD3DXBUFFER *ppVertexRemap) PURE;
  288.     STDMETHOD(SetAttributeTable)(THIS_ CONST D3DXATTRIBUTERANGE *pAttribTable, DWORD cAttribTableSize) PURE;
  289. };
  290.  
  291.  
  292. #undef INTERFACE
  293. #define INTERFACE ID3DXPMesh
  294.  
  295. DECLARE_INTERFACE_(ID3DXPMesh, ID3DXBaseMesh)
  296. {
  297.     // IUnknown
  298.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  299.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  300.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  301.  
  302.     // ID3DXBaseMesh
  303.     STDMETHOD(DrawSubset)(THIS_ DWORD AttribId) PURE;
  304.     STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE;
  305.     STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE;
  306.     STDMETHOD_(DWORD, GetFVF)(THIS) PURE;
  307.     STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  308.     STDMETHOD_(DWORD, GetNumBytesPerVertex)(THIS) PURE;
  309.     STDMETHOD_(DWORD, GetOptions)(THIS) PURE;
  310.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
  311.     STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, 
  312.                 DWORD FVF, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXMESH* ppCloneMesh) PURE;
  313.     STDMETHOD(CloneMesh)(THIS_ DWORD Options, 
  314.                 CONST D3DVERTEXELEMENT9 *pDeclaration, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXMESH* ppCloneMesh) PURE;
  315.     STDMETHOD(GetVertexBuffer)(THIS_ LPDIRECT3DVERTEXBUFFER9* ppVB) PURE;
  316.     STDMETHOD(GetIndexBuffer)(THIS_ LPDIRECT3DINDEXBUFFER9* ppIB) PURE;
  317.     STDMETHOD(LockVertexBuffer)(THIS_ DWORD Flags, LPVOID *ppData) PURE;
  318.     STDMETHOD(UnlockVertexBuffer)(THIS) PURE;
  319.     STDMETHOD(LockIndexBuffer)(THIS_ DWORD Flags, LPVOID *ppData) PURE;
  320.     STDMETHOD(UnlockIndexBuffer)(THIS) PURE;
  321.     STDMETHOD(GetAttributeTable)(
  322.                 THIS_ D3DXATTRIBUTERANGE *pAttribTable, DWORD* pAttribTableSize) PURE;
  323.  
  324.     STDMETHOD(ConvertPointRepsToAdjacency)(THIS_ CONST DWORD* pPRep, DWORD* pAdjacency) PURE;
  325.     STDMETHOD(ConvertAdjacencyToPointReps)(THIS_ CONST DWORD* pAdjacency, DWORD* pPRep) PURE;
  326.     STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Epsilon, DWORD* pAdjacency) PURE;
  327.  
  328.     STDMETHOD(UpdateSemantics)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  329.  
  330.     // ID3DXPMesh
  331.     STDMETHOD(ClonePMeshFVF)(THIS_ DWORD Options, 
  332.                 DWORD FVF, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXPMESH* ppCloneMesh) PURE;
  333.     STDMETHOD(ClonePMesh)(THIS_ DWORD Options, 
  334.                 CONST D3DVERTEXELEMENT9 *pDeclaration, LPDIRECT3DDEVICE9 pD3DDevice, LPD3DXPMESH* ppCloneMesh) PURE;
  335.     STDMETHOD(SetNumFaces)(THIS_ DWORD Faces) PURE;
  336.     STDMETHOD(SetNumVertices)(THIS_ DWORD Vertices) PURE;
  337.     STDMETHOD_(DWORD, GetMaxFaces)(THIS) PURE;
  338.     STDMETHOD_(DWORD, GetMinFaces)(THIS) PURE;
  339.     STDMETHOD_(DWORD, GetMaxVertices)(THIS) PURE;
  340.     STDMETHOD_(DWORD, GetMinVertices)(THIS) PURE;
  341.     STDMETHOD(Save)(THIS_ IStream *pStream, CONST D3DXMATERIAL* pMaterials, CONST D3DXEFFECTINSTANCE* pEffectInstances, DWORD NumMaterials) PURE;
  342.  
  343.     STDMETHOD(Optimize)(THIS_ DWORD Flags, DWORD* pAdjacencyOut, 
  344.                      DWORD* pFaceRemap, LPD3DXBUFFER *ppVertexRemap,  
  345.                      LPD3DXMESH* ppOptMesh) PURE;
  346.  
  347.     STDMETHOD(OptimizeBaseLOD)(THIS_ DWORD Flags, DWORD* pFaceRemap) PURE;
  348.     STDMETHOD(TrimByFaces)(THIS_ DWORD NewFacesMin, DWORD NewFacesMax, DWORD *rgiFaceRemap, DWORD *rgiVertRemap) PURE;
  349.     STDMETHOD(TrimByVertices)(THIS_ DWORD NewVerticesMin, DWORD NewVerticesMax, DWORD *rgiFaceRemap, DWORD *rgiVertRemap) PURE;
  350.  
  351.     STDMETHOD(GetAdjacency)(THIS_ DWORD* pAdjacency) PURE;
  352.  
  353.     //  Used to generate the immediate "ancestor" for each vertex when it is removed by a vsplit.  Allows generation of geomorphs
  354.     //     Vertex buffer must be equal to or greater than the maximum number of vertices in the pmesh
  355.     STDMETHOD(GenerateVertexHistory)(THIS_ DWORD* pVertexHistory) PURE;
  356. };
  357.  
  358.  
  359. #undef INTERFACE
  360. #define INTERFACE ID3DXSPMesh
  361.  
  362. DECLARE_INTERFACE_(ID3DXSPMesh, IUnknown)
  363. {
  364.     // IUnknown
  365.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  366.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  367.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  368.  
  369.     // ID3DXSPMesh
  370.     STDMETHOD_(DWORD, GetNumFaces)(THIS) PURE;
  371.     STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE;
  372.     STDMETHOD_(DWORD, GetFVF)(THIS) PURE;
  373.     STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  374.     STDMETHOD_(DWORD, GetOptions)(THIS) PURE;
  375.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
  376.     STDMETHOD(CloneMeshFVF)(THIS_ DWORD Options, 
  377.                 DWORD FVF, LPDIRECT3DDEVICE9 pD3DDevice, DWORD *pAdjacencyOut, DWORD *pVertexRemapOut, LPD3DXMESH* ppCloneMesh) PURE;
  378.     STDMETHOD(CloneMesh)(THIS_ DWORD Options, 
  379.                 CONST D3DVERTEXELEMENT9 *pDeclaration, LPDIRECT3DDEVICE9 pD3DDevice, DWORD *pAdjacencyOut, DWORD *pVertexRemapOut, LPD3DXMESH* ppCloneMesh) PURE;
  380.     STDMETHOD(ClonePMeshFVF)(THIS_ DWORD Options, 
  381.                 DWORD FVF, LPDIRECT3DDEVICE9 pD3DDevice, DWORD *pVertexRemapOut, FLOAT *pErrorsByFace, LPD3DXPMESH* ppCloneMesh) PURE;
  382.     STDMETHOD(ClonePMesh)(THIS_ DWORD Options, 
  383.                 CONST D3DVERTEXELEMENT9 *pDeclaration, LPDIRECT3DDEVICE9 pD3DDevice, DWORD *pVertexRemapOut, FLOAT *pErrorsbyFace, LPD3DXPMESH* ppCloneMesh) PURE;
  384.     STDMETHOD(ReduceFaces)(THIS_ DWORD Faces) PURE;
  385.     STDMETHOD(ReduceVertices)(THIS_ DWORD Vertices) PURE;
  386.     STDMETHOD_(DWORD, GetMaxFaces)(THIS) PURE;
  387.     STDMETHOD_(DWORD, GetMaxVertices)(THIS) PURE;
  388.     STDMETHOD(GetVertexAttributeWeights)(THIS_ LPD3DXATTRIBUTEWEIGHTS pVertexAttributeWeights) PURE;
  389.     STDMETHOD(GetVertexWeights)(THIS_ FLOAT *pVertexWeights) PURE;
  390. };
  391.  
  392. #define UNUSED16 (0xffff)
  393. #define UNUSED32 (0xffffffff)
  394.  
  395. // ID3DXMesh::Optimize options - upper byte only, lower 3 bytes used from _D3DXMESH option flags
  396. enum _D3DXMESHOPT {
  397.     D3DXMESHOPT_COMPACT       = 0x01000000,
  398.     D3DXMESHOPT_ATTRSORT      = 0x02000000,
  399.     D3DXMESHOPT_VERTEXCACHE   = 0x04000000,
  400.     D3DXMESHOPT_STRIPREORDER  = 0x08000000,
  401.     D3DXMESHOPT_IGNOREVERTS   = 0x10000000,  // optimize faces only, don't touch vertices
  402.     D3DXMESHOPT_DONOTSPLIT    = 0x20000000,  // do not split vertices shared between attribute groups when attribute sorting
  403.     D3DXMESHOPT_DEVICEINDEPENDENT = 0x00400000,  // Only affects VCache.  uses a static known good cache size for all cards
  404.                             
  405.     // D3DXMESHOPT_SHAREVB has been removed, please use D3DXMESH_VB_SHARE instead
  406.  
  407. };
  408.  
  409. // Subset of the mesh that has the same attribute and bone combination.
  410. // This subset can be rendered in a single draw call
  411. typedef struct _D3DXBONECOMBINATION
  412. {
  413.     DWORD AttribId;
  414.     DWORD FaceStart;
  415.     DWORD FaceCount;
  416.     DWORD VertexStart;
  417.     DWORD VertexCount;
  418.     DWORD* BoneId;
  419. } D3DXBONECOMBINATION, *LPD3DXBONECOMBINATION;
  420.  
  421. // The following types of patch combinations are supported:
  422. // Patch type   Basis       Degree
  423. // Rect         Bezier      2,3,5
  424. // Rect         B-Spline    2,3,5
  425. // Rect         Catmull-Rom 3
  426. // Tri          Bezier      2,3,5
  427. // N-Patch      N/A         3
  428.  
  429. typedef struct _D3DXPATCHINFO
  430. {
  431.     D3DXPATCHMESHTYPE PatchType;
  432.     D3DDEGREETYPE Degree;
  433.     D3DBASISTYPE Basis;
  434. } D3DXPATCHINFO, *LPD3DXPATCHINFO;
  435.  
  436. #undef INTERFACE
  437. #define INTERFACE ID3DXPatchMesh
  438.  
  439. DECLARE_INTERFACE_(ID3DXPatchMesh, IUnknown)
  440. {
  441.     // IUnknown
  442.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  443.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  444.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  445.  
  446.     // ID3DXPatchMesh
  447.  
  448.     // Return creation parameters
  449.     STDMETHOD_(DWORD, GetNumPatches)(THIS) PURE;
  450.     STDMETHOD_(DWORD, GetNumVertices)(THIS) PURE;
  451.     STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  452.     STDMETHOD_(DWORD, GetControlVerticesPerPatch)(THIS) PURE;
  453.     STDMETHOD_(DWORD, GetOptions)(THIS) PURE;
  454.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9 *ppDevice) PURE;
  455.     STDMETHOD(GetPatchInfo)(THIS_ LPD3DXPATCHINFO PatchInfo) PURE;
  456.  
  457.     // Control mesh access    
  458.     STDMETHOD(GetVertexBuffer)(THIS_ LPDIRECT3DVERTEXBUFFER9* ppVB) PURE;
  459.     STDMETHOD(GetIndexBuffer)(THIS_ LPDIRECT3DINDEXBUFFER9* ppIB) PURE;
  460.     STDMETHOD(LockVertexBuffer)(THIS_ DWORD flags, LPVOID *ppData) PURE;
  461.     STDMETHOD(UnlockVertexBuffer)(THIS) PURE;
  462.     STDMETHOD(LockIndexBuffer)(THIS_ DWORD flags, LPVOID *ppData) PURE;
  463.     STDMETHOD(UnlockIndexBuffer)(THIS) PURE;
  464.     STDMETHOD(LockAttributeBuffer)(THIS_ DWORD flags, DWORD** ppData) PURE;
  465.     STDMETHOD(UnlockAttributeBuffer)(THIS) PURE;
  466.  
  467.     // This function returns the size of the tessellated mesh given a tessellation level.
  468.     // This assumes uniform tessellation. For adaptive tessellation the Adaptive parameter must
  469.     // be set to TRUE and TessellationLevel should be the max tessellation.
  470.     // This will result in the max mesh size necessary for adaptive tessellation.    
  471.     STDMETHOD(GetTessSize)(THIS_ FLOAT fTessLevel,DWORD Adaptive, DWORD *NumTriangles,DWORD *NumVertices) PURE;
  472.     
  473.     //GenerateAdjacency determines which patches are adjacent with provided tolerance
  474.     //this information is used internally to optimize tessellation
  475.     STDMETHOD(GenerateAdjacency)(THIS_ FLOAT Tolerance) PURE;
  476.     
  477.     //CloneMesh Creates a new patchmesh with the specified decl, and converts the vertex buffer
  478.     //to the new decl. Entries in the new decl which are new are set to 0. If the current mesh
  479.     //has adjacency, the new mesh will also have adjacency
  480.     STDMETHOD(CloneMesh)(THIS_ DWORD Options, CONST D3DVERTEXELEMENT9 *pDecl, LPD3DXPATCHMESH *pMesh) PURE;
  481.     
  482.     // Optimizes the patchmesh for efficient tessellation. This function is designed
  483.     // to perform one time optimization for patch meshes that need to be tessellated
  484.     // repeatedly by calling the Tessellate() method. The optimization performed is
  485.     // independent of the actual tessellation level used.
  486.     // Currently Flags is unused.
  487.     // If vertices are changed, Optimize must be called again
  488.     STDMETHOD(Optimize)(THIS_ DWORD flags) PURE;
  489.  
  490.     //gets and sets displacement parameters
  491.     //displacement maps can only be 2D textures MIP-MAPPING is ignored for non adapative tessellation
  492.     STDMETHOD(SetDisplaceParam)(THIS_ LPDIRECT3DBASETEXTURE9 Texture,
  493.                               D3DTEXTUREFILTERTYPE MinFilter,
  494.                               D3DTEXTUREFILTERTYPE MagFilter,
  495.                               D3DTEXTUREFILTERTYPE MipFilter,
  496.                               D3DTEXTUREADDRESS Wrap,
  497.                               DWORD dwLODBias) PURE;
  498.  
  499.     STDMETHOD(GetDisplaceParam)(THIS_ LPDIRECT3DBASETEXTURE9 *Texture,
  500.                                 D3DTEXTUREFILTERTYPE *MinFilter,
  501.                                 D3DTEXTUREFILTERTYPE *MagFilter,
  502.                                 D3DTEXTUREFILTERTYPE *MipFilter,
  503.                                 D3DTEXTUREADDRESS *Wrap,
  504.                                 DWORD *dwLODBias) PURE;
  505.         
  506.     // Performs the uniform tessellation based on the tessellation level. 
  507.     // This function will perform more efficiently if the patch mesh has been optimized using the Optimize() call.
  508.     STDMETHOD(Tessellate)(THIS_ FLOAT fTessLevel,LPD3DXMESH pMesh) PURE;
  509.  
  510.     // Performs adaptive tessellation based on the Z based adaptive tessellation criterion.
  511.     // pTrans specifies a 4D vector that is dotted with the vertices to get the per vertex
  512.     // adaptive tessellation amount. Each edge is tessellated to the average of the criterion
  513.     // at the 2 vertices it connects.
  514.     // MaxTessLevel specifies the upper limit for adaptive tesselation.
  515.     // This function will perform more efficiently if the patch mesh has been optimized using the Optimize() call.
  516.     STDMETHOD(TessellateAdaptive)(THIS_ 
  517.         CONST D3DXVECTOR4 *pTrans,
  518.         DWORD dwMaxTessLevel, 
  519.         DWORD dwMinTessLevel,
  520.         LPD3DXMESH pMesh) PURE;
  521.  
  522. };
  523.  
  524. #undef INTERFACE
  525. #define INTERFACE ID3DXSkinInfo
  526.  
  527. DECLARE_INTERFACE_(ID3DXSkinInfo, IUnknown)
  528. {
  529.     // IUnknown
  530.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  531.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  532.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  533.  
  534.     // Specify the which vertices do each bones influence and by how much
  535.     STDMETHOD(SetBoneInfluence)(THIS_ DWORD bone, DWORD numInfluences, CONST DWORD* vertices, CONST FLOAT* weights) PURE;
  536.     STDMETHOD(SetBoneVertexInfluence)(THIS_ DWORD boneNum, DWORD influenceNum, float weight) PURE;
  537.     STDMETHOD_(DWORD, GetNumBoneInfluences)(THIS_ DWORD bone) PURE;
  538.     STDMETHOD(GetBoneInfluence)(THIS_ DWORD bone, DWORD* vertices, FLOAT* weights) PURE;
  539.     STDMETHOD(GetBoneVertexInfluence)(THIS_ DWORD boneNum, DWORD influenceNum, float *pWeight, DWORD *pVertexNum) PURE;
  540.     STDMETHOD(GetMaxVertexInfluences)(THIS_ DWORD* maxVertexInfluences) PURE;
  541.     STDMETHOD_(DWORD, GetNumBones)(THIS) PURE;
  542.     STDMETHOD(FindBoneVertexInfluenceIndex)(THIS_ DWORD boneNum, DWORD vertexNum, DWORD *pInfluenceIndex) PURE;
  543.  
  544.     // This gets the max face influences based on a triangle mesh with the specified index buffer
  545.     STDMETHOD(GetMaxFaceInfluences)(THIS_ LPDIRECT3DINDEXBUFFER9 pIB, DWORD NumFaces, DWORD* maxFaceInfluences) PURE;
  546.     
  547.     // Set min bone influence. Bone influences that are smaller than this are ignored
  548.     STDMETHOD(SetMinBoneInfluence)(THIS_ FLOAT MinInfl) PURE;
  549.     // Get min bone influence. 
  550.     STDMETHOD_(FLOAT, GetMinBoneInfluence)(THIS) PURE;
  551.     
  552.     // Bone names are returned by D3DXLoadSkinMeshFromXof. They are not used by any other method of this object
  553.     STDMETHOD(SetBoneName)(THIS_ DWORD Bone, LPCSTR pName) PURE; // pName is copied to an internal string buffer
  554.     STDMETHOD_(LPCSTR, GetBoneName)(THIS_ DWORD Bone) PURE; // A pointer to an internal string buffer is returned. Do not free this.
  555.     
  556.     // Bone offset matrices are returned by D3DXLoadSkinMeshFromXof. They are not used by any other method of this object
  557.     STDMETHOD(SetBoneOffsetMatrix)(THIS_ DWORD Bone, CONST D3DXMATRIX *pBoneTransform) PURE; // pBoneTransform is copied to an internal buffer
  558.     STDMETHOD_(LPD3DXMATRIX, GetBoneOffsetMatrix)(THIS_ DWORD Bone) PURE; // A pointer to an internal matrix is returned. Do not free this.
  559.     
  560.     // Clone a skin info object
  561.     STDMETHOD(Clone)(THIS_ LPD3DXSKININFO* ppSkinInfo) PURE;
  562.     
  563.     // Update bone influence information to match vertices after they are reordered. This should be called 
  564.     // if the target vertex buffer has been reordered externally.
  565.     STDMETHOD(Remap)(THIS_ DWORD NumVertices, DWORD* pVertexRemap) PURE;
  566.  
  567.     // These methods enable the modification of the vertex layout of the vertices that will be skinned
  568.     STDMETHOD(SetFVF)(THIS_ DWORD FVF) PURE;
  569.     STDMETHOD(SetDeclaration)(THIS_ CONST D3DVERTEXELEMENT9 *pDeclaration) PURE;
  570.     STDMETHOD_(DWORD, GetFVF)(THIS) PURE;
  571.     STDMETHOD(GetDeclaration)(THIS_ D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE]) PURE;
  572.  
  573.     // Apply SW skinning based on current pose matrices to the target vertices.
  574.     STDMETHOD(UpdateSkinnedMesh)(THIS_ 
  575.         CONST D3DXMATRIX* pBoneTransforms, 
  576.         CONST D3DXMATRIX* pBoneInvTransposeTransforms, 
  577.         LPCVOID pVerticesSrc, 
  578.         PVOID pVerticesDst) PURE;
  579.  
  580.     // Takes a mesh and returns a new mesh with per vertex blend weights and a bone combination
  581.     // table that describes which bones affect which subsets of the mesh
  582.     STDMETHOD(ConvertToBlendedMesh)(THIS_ 
  583.         LPD3DXMESH pMesh,
  584.         DWORD Options, 
  585.         CONST DWORD *pAdjacencyIn, 
  586.         LPDWORD pAdjacencyOut,
  587.         DWORD* pFaceRemap, 
  588.         LPD3DXBUFFER *ppVertexRemap, 
  589.         DWORD* pMaxFaceInfl,
  590.         DWORD* pNumBoneCombinations, 
  591.         LPD3DXBUFFER* ppBoneCombinationTable, 
  592.         LPD3DXMESH* ppMesh) PURE;
  593.  
  594.     // Takes a mesh and returns a new mesh with per vertex blend weights and indices 
  595.     // and a bone combination table that describes which bones palettes affect which subsets of the mesh
  596.     STDMETHOD(ConvertToIndexedBlendedMesh)(THIS_ 
  597.         LPD3DXMESH pMesh,
  598.         DWORD Options, 
  599.         DWORD paletteSize, 
  600.         CONST DWORD *pAdjacencyIn, 
  601.         LPDWORD pAdjacencyOut, 
  602.         DWORD* pFaceRemap, 
  603.         LPD3DXBUFFER *ppVertexRemap, 
  604.         DWORD* pMaxVertexInfl,
  605.         DWORD* pNumBoneCombinations, 
  606.         LPD3DXBUFFER* ppBoneCombinationTable, 
  607.         LPD3DXMESH* ppMesh) PURE;
  608. };
  609.  
  610. #ifdef __cplusplus
  611. extern "C" {
  612. #endif //__cplusplus
  613.  
  614.  
  615. HRESULT WINAPI 
  616.     D3DXCreateMesh(
  617.         DWORD NumFaces, 
  618.         DWORD NumVertices, 
  619.         DWORD Options, 
  620.         CONST D3DVERTEXELEMENT9 *pDeclaration, 
  621.         LPDIRECT3DDEVICE9 pD3DDevice, 
  622.         LPD3DXMESH* ppMesh);
  623.  
  624. HRESULT WINAPI 
  625.     D3DXCreateMeshFVF(
  626.         DWORD NumFaces, 
  627.         DWORD NumVertices, 
  628.         DWORD Options, 
  629.         DWORD FVF, 
  630.         LPDIRECT3DDEVICE9 pD3DDevice, 
  631.         LPD3DXMESH* ppMesh);
  632.  
  633. HRESULT WINAPI 
  634.     D3DXCreateSPMesh(
  635.         LPD3DXMESH pMesh, 
  636.         CONST DWORD* pAdjacency, 
  637.         CONST D3DXATTRIBUTEWEIGHTS *pVertexAttributeWeights,
  638.         CONST FLOAT *pVertexWeights,
  639.         LPD3DXSPMESH* ppSMesh);
  640.  
  641. // clean a mesh up for simplification, try to make manifold
  642. HRESULT WINAPI
  643.     D3DXCleanMesh(
  644.     D3DXCLEANTYPE CleanType,
  645.     LPD3DXMESH pMeshIn,
  646.     CONST DWORD* pAdjacencyIn,
  647.     LPD3DXMESH* ppMeshOut,
  648.     DWORD* pAdjacencyOut,
  649.     LPD3DXBUFFER* ppErrorsAndWarnings);
  650.  
  651. HRESULT WINAPI
  652.     D3DXValidMesh(
  653.     LPD3DXMESH pMeshIn,
  654.     CONST DWORD* pAdjacency,
  655.     LPD3DXBUFFER* ppErrorsAndWarnings);
  656.  
  657. HRESULT WINAPI 
  658.     D3DXGeneratePMesh(
  659.         LPD3DXMESH pMesh, 
  660.         CONST DWORD* pAdjacency, 
  661.         CONST D3DXATTRIBUTEWEIGHTS *pVertexAttributeWeights,
  662.         CONST FLOAT *pVertexWeights,
  663.         DWORD MinValue, 
  664.         DWORD Options, 
  665.         LPD3DXPMESH* ppPMesh);
  666.  
  667. HRESULT WINAPI 
  668.     D3DXSimplifyMesh(
  669.         LPD3DXMESH pMesh, 
  670.         CONST DWORD* pAdjacency, 
  671.         CONST D3DXATTRIBUTEWEIGHTS *pVertexAttributeWeights,
  672.         CONST FLOAT *pVertexWeights,
  673.         DWORD MinValue, 
  674.         DWORD Options, 
  675.         LPD3DXMESH* ppMesh);
  676.  
  677. HRESULT WINAPI 
  678.     D3DXComputeBoundingSphere(
  679.         CONST D3DXVECTOR3 *pFirstPosition,  // pointer to first position
  680.         DWORD NumVertices, 
  681.         DWORD dwStride,                     // count in bytes to subsequent position vectors
  682.         D3DXVECTOR3 *pCenter, 
  683.         FLOAT *pRadius);
  684.  
  685. HRESULT WINAPI 
  686.     D3DXComputeBoundingBox(
  687.         CONST D3DXVECTOR3 *pFirstPosition,  // pointer to first position
  688.         DWORD NumVertices, 
  689.         DWORD dwStride,                     // count in bytes to subsequent position vectors
  690.         D3DXVECTOR3 *pMin, 
  691.         D3DXVECTOR3 *pMax);
  692.  
  693. HRESULT WINAPI 
  694.     D3DXComputeNormals(
  695.         LPD3DXBASEMESH pMesh,
  696.         CONST DWORD *pAdjacency);
  697.  
  698. HRESULT WINAPI 
  699.     D3DXCreateBuffer(
  700.         DWORD NumBytes, 
  701.         LPD3DXBUFFER *ppBuffer);
  702.  
  703.  
  704. HRESULT WINAPI
  705.     D3DXLoadMeshFromXA(
  706.         LPCSTR pFilename, 
  707.         DWORD Options, 
  708.         LPDIRECT3DDEVICE9 pD3DDevice, 
  709.         LPD3DXBUFFER *ppAdjacency,
  710.         LPD3DXBUFFER *ppMaterials, 
  711.         LPD3DXBUFFER *ppEffectInstances, 
  712.         DWORD *pNumMaterials,
  713.         LPD3DXMESH *ppMesh);
  714.  
  715. HRESULT WINAPI
  716.     D3DXLoadMeshFromXW(
  717.         LPCWSTR pFilename, 
  718.         DWORD Options, 
  719.         LPDIRECT3DDEVICE9 pD3DDevice, 
  720.         LPD3DXBUFFER *ppAdjacency,
  721.         LPD3DXBUFFER *ppMaterials, 
  722.         LPD3DXBUFFER *ppEffectInstances, 
  723.         DWORD *pNumMaterials,
  724.         LPD3DXMESH *ppMesh);
  725.  
  726. #ifdef UNICODE
  727. #define D3DXLoadMeshFromX D3DXLoadMeshFromXW
  728. #else
  729. #define D3DXLoadMeshFromX D3DXLoadMeshFromXA
  730. #endif
  731.  
  732. HRESULT WINAPI 
  733.     D3DXLoadMeshFromXInMemory(
  734.         LPCVOID Memory,
  735.         DWORD SizeOfMemory,
  736.         DWORD Options, 
  737.         LPDIRECT3DDEVICE9 pD3DDevice, 
  738.         LPD3DXBUFFER *ppAdjacency,
  739.         LPD3DXBUFFER *ppMaterials, 
  740.         LPD3DXBUFFER *ppEffectInstances, 
  741.         DWORD *pNumMaterials,
  742.         LPD3DXMESH *ppMesh);
  743.  
  744. HRESULT WINAPI 
  745.     D3DXLoadMeshFromXResource(
  746.         HMODULE Module,
  747.         LPCSTR Name,
  748.         LPCSTR Type,
  749.         DWORD Options, 
  750.         LPDIRECT3DDEVICE9 pD3DDevice, 
  751.         LPD3DXBUFFER *ppAdjacency,
  752.         LPD3DXBUFFER *ppMaterials, 
  753.         LPD3DXBUFFER *ppEffectInstances, 
  754.         DWORD *pNumMaterials,
  755.         LPD3DXMESH *ppMesh);
  756.  
  757. HRESULT WINAPI 
  758.     D3DXSaveMeshToXA(
  759.         LPCSTR pFilename,
  760.         LPD3DXMESH pMesh,
  761.         CONST DWORD* pAdjacency,
  762.         CONST D3DXMATERIAL* pMaterials,
  763.         CONST D3DXEFFECTINSTANCE* pEffectInstances, 
  764.         DWORD NumMaterials,
  765.         DWORD Format
  766.         );
  767.  
  768. HRESULT WINAPI 
  769.     D3DXSaveMeshToXW(
  770.         LPCWSTR pFilename,
  771.         LPD3DXMESH pMesh,
  772.         CONST DWORD* pAdjacency,
  773.         CONST D3DXMATERIAL* pMaterials,
  774.         CONST D3DXEFFECTINSTANCE* pEffectInstances, 
  775.         DWORD NumMaterials,
  776.         DWORD Format
  777.         );
  778.         
  779. #ifdef UNICODE
  780. #define D3DXSaveMeshToX D3DXSaveMeshToXW
  781. #else
  782. #define D3DXSaveMeshToX D3DXSaveMeshToXA
  783. #endif
  784.         
  785.  
  786. HRESULT WINAPI 
  787.     D3DXCreatePMeshFromStream(
  788.         IStream *pStream, 
  789.         DWORD Options,
  790.         LPDIRECT3DDEVICE9 pD3DDevice, 
  791.         LPD3DXBUFFER *ppMaterials,
  792.         LPD3DXBUFFER *ppEffectInstances, 
  793.         DWORD* pNumMaterials,
  794.         LPD3DXPMESH *ppPMesh);
  795.  
  796. // Creates a skin info object based on the number of vertices, number of bones, and a declaration describing the vertex layout of the target vertices
  797. // The bone names and initial bone transforms are not filled in the skin info object by this method.
  798. HRESULT WINAPI
  799.     D3DXCreateSkinInfo(
  800.         DWORD NumVertices,
  801.         CONST D3DVERTEXELEMENT9 *pDeclaration, 
  802.         DWORD NumBones,
  803.         LPD3DXSKININFO* ppSkinInfo);
  804.         
  805. // Creates a skin info object based on the number of vertices, number of bones, and a FVF describing the vertex layout of the target vertices
  806. // The bone names and initial bone transforms are not filled in the skin info object by this method.
  807. HRESULT WINAPI
  808.     D3DXCreateSkinInfoFVF(
  809.         DWORD NumVertices,
  810.         DWORD FVF,
  811.         DWORD NumBones,
  812.         LPD3DXSKININFO* ppSkinInfo);
  813.         
  814. #ifdef __cplusplus
  815. }
  816.  
  817. extern "C" {
  818. #endif //__cplusplus
  819.  
  820. HRESULT WINAPI 
  821.     D3DXLoadMeshFromXof(
  822.         LPD3DXFILEDATA pxofMesh, 
  823.         DWORD Options, 
  824.         LPDIRECT3DDEVICE9 pD3DDevice, 
  825.         LPD3DXBUFFER *ppAdjacency,
  826.         LPD3DXBUFFER *ppMaterials, 
  827.         LPD3DXBUFFER *ppEffectInstances, 
  828.         DWORD *pNumMaterials,
  829.         LPD3DXMESH *ppMesh);
  830.  
  831. // This similar to D3DXLoadMeshFromXof, except also returns skinning info if present in the file
  832. // If skinning info is not present, ppSkinInfo will be NULL     
  833. HRESULT WINAPI
  834.     D3DXLoadSkinMeshFromXof(
  835.         LPD3DXFILEDATA pxofMesh, 
  836.         DWORD Options,
  837.         LPDIRECT3DDEVICE9 pD3DDevice,
  838.         LPD3DXBUFFER* ppAdjacency,
  839.         LPD3DXBUFFER* ppMaterials,
  840.         LPD3DXBUFFER *ppEffectInstances, 
  841.         DWORD *pMatOut,
  842.         LPD3DXSKININFO* ppSkinInfo,
  843.         LPD3DXMESH* ppMesh);
  844.  
  845.  
  846. // The inverse of D3DXConvertTo{Indexed}BlendedMesh() functions. It figures out the skinning info from
  847. // the mesh and the bone combination table and populates a skin info object with that data. The bone
  848. // names and initial bone transforms are not filled in the skin info object by this method. This works
  849. // with either a non-indexed or indexed blended mesh. It examines the FVF or declarator of the mesh to
  850. // determine what type it is.
  851. HRESULT WINAPI
  852.     D3DXCreateSkinInfoFromBlendedMesh(
  853.         LPD3DXBASEMESH pMesh,
  854.         DWORD NumBones,
  855.         CONST D3DXBONECOMBINATION *pBoneCombinationTable,
  856.         LPD3DXSKININFO* ppSkinInfo);
  857.         
  858. HRESULT WINAPI
  859.     D3DXTessellateNPatches(
  860.         LPD3DXMESH pMeshIn,             
  861.         CONST DWORD* pAdjacencyIn,             
  862.         FLOAT NumSegs,                    
  863.         BOOL  QuadraticInterpNormals,     // if false use linear intrep for normals, if true use quadratic
  864.         LPD3DXMESH *ppMeshOut,
  865.         LPD3DXBUFFER *ppAdjacencyOut);
  866.  
  867.  
  868. //generates implied outputdecl from input decl
  869. //the decl generated from this should be used to generate the output decl for
  870. //the tessellator subroutines. 
  871.  
  872. HRESULT WINAPI
  873.     D3DXGenerateOutputDecl(
  874.         D3DVERTEXELEMENT9 *pOutput,
  875.         CONST D3DVERTEXELEMENT9 *pInput);
  876.  
  877. //loads patches from an XFileData
  878. //since an X file can have up to 6 different patch meshes in it,
  879. //returns them in an array - pNumPatches will contain the number of
  880. //meshes in the actual file. 
  881. HRESULT WINAPI
  882.     D3DXLoadPatchMeshFromXof(
  883.         LPD3DXFILEDATA pXofObjMesh,
  884.         DWORD Options,
  885.         LPDIRECT3DDEVICE9 pD3DDevice,
  886.         LPD3DXBUFFER *ppMaterials,
  887.         LPD3DXBUFFER *ppEffectInstances, 
  888.         PDWORD pNumMaterials,
  889.         LPD3DXPATCHMESH *ppMesh);
  890.  
  891. //computes the size a single rect patch.
  892. HRESULT WINAPI
  893.     D3DXRectPatchSize(
  894.         CONST FLOAT *pfNumSegs, //segments for each edge (4)
  895.         DWORD *pdwTriangles,    //output number of triangles
  896.         DWORD *pdwVertices);    //output number of vertices
  897.  
  898. //computes the size of a single triangle patch      
  899. HRESULT WINAPI
  900.     D3DXTriPatchSize(
  901.         CONST FLOAT *pfNumSegs, //segments for each edge (3)    
  902.         DWORD *pdwTriangles,    //output number of triangles
  903.         DWORD *pdwVertices);    //output number of vertices
  904.  
  905.  
  906. //tessellates a patch into a created mesh
  907. //similar to D3D RT patch
  908. HRESULT WINAPI
  909.     D3DXTessellateRectPatch(
  910.         LPDIRECT3DVERTEXBUFFER9 pVB,
  911.         CONST FLOAT *pNumSegs,
  912.         CONST D3DVERTEXELEMENT9 *pdwInDecl,
  913.         CONST D3DRECTPATCH_INFO *pRectPatchInfo,
  914.         LPD3DXMESH pMesh);
  915.  
  916.  
  917. HRESULT WINAPI
  918.     D3DXTessellateTriPatch(
  919.       LPDIRECT3DVERTEXBUFFER9 pVB,
  920.       CONST FLOAT *pNumSegs,
  921.       CONST D3DVERTEXELEMENT9 *pInDecl,
  922.       CONST D3DTRIPATCH_INFO *pTriPatchInfo,
  923.       LPD3DXMESH pMesh);
  924.  
  925.  
  926.  
  927. //creates an NPatch PatchMesh from a D3DXMESH 
  928. HRESULT WINAPI
  929.     D3DXCreateNPatchMesh(
  930.         LPD3DXMESH pMeshSysMem,
  931.         LPD3DXPATCHMESH *pPatchMesh);
  932.  
  933.       
  934. //creates a patch mesh
  935. HRESULT WINAPI
  936.     D3DXCreatePatchMesh(
  937.         CONST D3DXPATCHINFO *pInfo,     //patch type
  938.         DWORD dwNumPatches,             //number of patches
  939.         DWORD dwNumVertices,            //number of control vertices
  940.         DWORD dwOptions,                //options 
  941.         CONST D3DVERTEXELEMENT9 *pDecl, //format of control vertices
  942.         LPDIRECT3DDEVICE9 pD3DDevice, 
  943.         LPD3DXPATCHMESH *pPatchMesh);
  944.  
  945.         
  946. //returns the number of degenerates in a patch mesh -
  947. //text output put in string.
  948. HRESULT WINAPI
  949.     D3DXValidPatchMesh(LPD3DXPATCHMESH pMesh,
  950.                         DWORD *dwcDegenerateVertices,
  951.                         DWORD *dwcDegeneratePatches,
  952.                         LPD3DXBUFFER *ppErrorsAndWarnings);
  953.  
  954. UINT WINAPI
  955.     D3DXGetFVFVertexSize(DWORD FVF);
  956.  
  957. UINT WINAPI 
  958.     D3DXGetDeclVertexSize(CONST D3DVERTEXELEMENT9 *pDecl,DWORD Stream);
  959.  
  960. UINT WINAPI 
  961.     D3DXGetDeclLength(CONST D3DVERTEXELEMENT9 *pDecl);
  962.  
  963. HRESULT WINAPI
  964.     D3DXDeclaratorFromFVF(
  965.         DWORD FVF,
  966.         D3DVERTEXELEMENT9 pDeclarator[MAX_FVF_DECL_SIZE]);
  967.  
  968. HRESULT WINAPI
  969.     D3DXFVFFromDeclarator(
  970.         CONST D3DVERTEXELEMENT9 *pDeclarator,
  971.         DWORD *pFVF);
  972.  
  973. HRESULT WINAPI 
  974.     D3DXWeldVertices(
  975.         LPD3DXMESH pMesh,         
  976.         DWORD Flags,
  977.         CONST D3DXWELDEPSILONS *pEpsilons,                 
  978.         CONST DWORD *pAdjacencyIn, 
  979.         DWORD *pAdjacencyOut,
  980.         DWORD *pFaceRemap, 
  981.         LPD3DXBUFFER *ppVertexRemap);
  982.  
  983. typedef struct _D3DXINTERSECTINFO
  984. {
  985.     DWORD FaceIndex;                // index of face intersected
  986.     FLOAT U;                        // Barycentric Hit Coordinates    
  987.     FLOAT V;                        // Barycentric Hit Coordinates
  988.     FLOAT Dist;                     // Ray-Intersection Parameter Distance
  989. } D3DXINTERSECTINFO, *LPD3DXINTERSECTINFO;
  990.  
  991.  
  992. HRESULT WINAPI
  993.     D3DXIntersect(
  994.         LPD3DXBASEMESH pMesh,
  995.         CONST D3DXVECTOR3 *pRayPos,
  996.         CONST D3DXVECTOR3 *pRayDir, 
  997.         BOOL    *pHit,              // True if any faces were intersected
  998.         DWORD   *pFaceIndex,        // index of closest face intersected
  999.         FLOAT   *pU,                // Barycentric Hit Coordinates    
  1000.         FLOAT   *pV,                // Barycentric Hit Coordinates
  1001.         FLOAT   *pDist,             // Ray-Intersection Parameter Distance
  1002.         LPD3DXBUFFER *ppAllHits,    // Array of D3DXINTERSECTINFOs for all hits (not just closest) 
  1003.         DWORD   *pCountOfHits);     // Number of entries in AllHits array
  1004.  
  1005. HRESULT WINAPI
  1006.     D3DXIntersectSubset(
  1007.         LPD3DXBASEMESH pMesh,
  1008.         DWORD AttribId,
  1009.         CONST D3DXVECTOR3 *pRayPos,
  1010.         CONST D3DXVECTOR3 *pRayDir, 
  1011.         BOOL    *pHit,              // True if any faces were intersected
  1012.         DWORD   *pFaceIndex,        // index of closest face intersected
  1013.         FLOAT   *pU,                // Barycentric Hit Coordinates    
  1014.         FLOAT   *pV,                // Barycentric Hit Coordinates
  1015.         FLOAT   *pDist,             // Ray-Intersection Parameter Distance
  1016.         LPD3DXBUFFER *ppAllHits,    // Array of D3DXINTERSECTINFOs for all hits (not just closest) 
  1017.         DWORD   *pCountOfHits);     // Number of entries in AllHits array
  1018.  
  1019.  
  1020. HRESULT WINAPI D3DXSplitMesh
  1021.     (
  1022.     LPD3DXMESH pMeshIn,         
  1023.     CONST DWORD *pAdjacencyIn, 
  1024.     CONST DWORD MaxSize,
  1025.     CONST DWORD Options,
  1026.     DWORD *pMeshesOut,
  1027.     LPD3DXBUFFER *ppMeshArrayOut,
  1028.     LPD3DXBUFFER *ppAdjacencyArrayOut,
  1029.     LPD3DXBUFFER *ppFaceRemapArrayOut,
  1030.     LPD3DXBUFFER *ppVertRemapArrayOut
  1031.     );
  1032.  
  1033. BOOL WINAPI D3DXIntersectTri 
  1034. (
  1035.     CONST D3DXVECTOR3 *p0,           // Triangle vertex 0 position
  1036.     CONST D3DXVECTOR3 *p1,           // Triangle vertex 1 position
  1037.     CONST D3DXVECTOR3 *p2,           // Triangle vertex 2 position
  1038.     CONST D3DXVECTOR3 *pRayPos,      // Ray origin
  1039.     CONST D3DXVECTOR3 *pRayDir,      // Ray direction
  1040.     FLOAT *pU,                       // Barycentric Hit Coordinates
  1041.     FLOAT *pV,                       // Barycentric Hit Coordinates
  1042.     FLOAT *pDist);                   // Ray-Intersection Parameter Distance
  1043.  
  1044. BOOL WINAPI
  1045.     D3DXSphereBoundProbe(
  1046.         CONST D3DXVECTOR3 *pCenter,
  1047.         FLOAT Radius,
  1048.         CONST D3DXVECTOR3 *pRayPosition,
  1049.         CONST D3DXVECTOR3 *pRayDirection);
  1050.  
  1051. BOOL WINAPI 
  1052.     D3DXBoxBoundProbe(
  1053.         CONST D3DXVECTOR3 *pMin, 
  1054.         CONST D3DXVECTOR3 *pMax,
  1055.         CONST D3DXVECTOR3 *pRayPosition,
  1056.         CONST D3DXVECTOR3 *pRayDirection);
  1057.  
  1058.  
  1059.  
  1060. //D3DXComputeTangent
  1061. //
  1062. //Computes the Tangent vectors for the TexStage texture coordinates
  1063. //and places the results in the TANGENT[TangentIndex] specified in the meshes' DECL
  1064. //puts the binorm in BINORM[BinormIndex] also specified in the decl.
  1065. //
  1066. //If neither the binorm or the tangnet are in the meshes declaration,
  1067. //the function will fail. 
  1068. //
  1069. //If a tangent or Binorm field is in the Decl, but the user does not
  1070. //wish D3DXComputeTangent to replace them, then D3DX_DEFAULT specified
  1071. //in the TangentIndex or BinormIndex will cause it to ignore the specified 
  1072. //semantic.
  1073. //
  1074. //Wrap should be specified if the texture coordinates wrap.
  1075.  
  1076. HRESULT WINAPI D3DXComputeTangent(LPD3DXMESH Mesh,
  1077.                                  DWORD TexStage,
  1078.                                  DWORD TangentIndex,
  1079.                                  DWORD BinormIndex,
  1080.                                  DWORD Wrap,
  1081.                                  CONST DWORD *pAdjacency);
  1082.  
  1083. HRESULT WINAPI
  1084.     D3DXConvertMeshSubsetToSingleStrip(
  1085.         LPD3DXBASEMESH MeshIn,
  1086.         DWORD AttribId,
  1087.         DWORD IBOptions,
  1088.         LPDIRECT3DINDEXBUFFER9 *ppIndexBuffer,
  1089.         DWORD *pNumIndices);
  1090.  
  1091. HRESULT WINAPI
  1092.     D3DXConvertMeshSubsetToStrips(
  1093.         LPD3DXBASEMESH MeshIn,
  1094.         DWORD AttribId,
  1095.         DWORD IBOptions,
  1096.         LPDIRECT3DINDEXBUFFER9 *ppIndexBuffer,
  1097.         DWORD *pNumIndices,
  1098.         LPD3DXBUFFER *ppStripLengths,
  1099.         DWORD *pNumStrips);
  1100.  
  1101.         
  1102. //============================================================================
  1103. //
  1104. //  D3DXOptimizeFaces:
  1105. //  --------------------
  1106. //  Generate a face remapping for a triangle list that more effectively utilizes
  1107. //    vertex caches.  This optimization is identical to the one provided
  1108. //    by ID3DXMesh::Optimize with the hardware independent option enabled.
  1109. //
  1110. //  Parameters:
  1111. //   pbIndices
  1112. //      Triangle list indices to use for generating a vertex ordering
  1113. //   NumFaces
  1114. //      Number of faces in the triangle list
  1115. //   NumVertices
  1116. //      Number of vertices referenced by the triangle list
  1117. //   b32BitIndices
  1118. //      TRUE if indices are 32 bit, FALSE if indices are 16 bit
  1119. //   pFaceRemap
  1120. //      Destination buffer to store face ordering
  1121. //      The number stored for a given element is where in the new ordering
  1122. //        the face will have come from.  See ID3DXMesh::Optimize for more info.
  1123. //
  1124. //============================================================================
  1125. HRESULT WINAPI
  1126.     D3DXOptimizeFaces(
  1127.         LPCVOID pbIndices, 
  1128.         UINT cFaces, 
  1129.         UINT cVertices, 
  1130.         BOOL b32BitIndices, 
  1131.         DWORD* pFaceRemap);
  1132.         
  1133. //============================================================================
  1134. //
  1135. //  D3DXOptimizeVertices:
  1136. //  --------------------
  1137. //  Generate a vertex remapping to optimize for in order use of vertices for 
  1138. //    a given set of indices.  This is commonly used after applying the face
  1139. //    remap generated by D3DXOptimizeFaces
  1140. //
  1141. //  Parameters:
  1142. //   pbIndices
  1143. //      Triangle list indices to use for generating a vertex ordering
  1144. //   NumFaces
  1145. //      Number of faces in the triangle list
  1146. //   NumVertices
  1147. //      Number of vertices referenced by the triangle list
  1148. //   b32BitIndices
  1149. //      TRUE if indices are 32 bit, FALSE if indices are 16 bit
  1150. //   pVertexRemap
  1151. //      Destination buffer to store vertex ordering
  1152. //      The number stored for a given element is where in the new ordering
  1153. //        the vertex will have come from.  See ID3DXMesh::Optimize for more info.
  1154. //
  1155. //============================================================================
  1156. HRESULT WINAPI
  1157.     D3DXOptimizeVertices(
  1158.         LPCVOID pbIndices, 
  1159.         UINT cFaces, 
  1160.         UINT cVertices, 
  1161.         BOOL b32BitIndices, 
  1162.         DWORD* pVertexRemap);
  1163.  
  1164. #ifdef __cplusplus
  1165. }
  1166. #endif //__cplusplus
  1167.  
  1168.  
  1169. //===========================================================================
  1170. //
  1171. //  Data structures for Spherical Harmonic Precomputation
  1172. //
  1173. //
  1174. //============================================================================
  1175.  
  1176. typedef enum _D3DXSHCOMPRESSQUALITYTYPE {
  1177.     D3DXSHCQUAL_FASTLOWQUALITY  = 1,
  1178.     D3DXSHCQUAL_SLOWHIGHQUALITY = 2,
  1179.     D3DXSHCQUAL_FORCE_DWORD     = 0x7fffffff
  1180. } D3DXSHCOMPRESSQUALITYTYPE;
  1181.  
  1182. typedef enum _D3DXSHGPUSIMOPT {
  1183.     D3DXSHGPUSIMOPT_SHADOWRES256  = 1,
  1184.     D3DXSHGPUSIMOPT_SHADOWRES512  = 0,
  1185.     D3DXSHGPUSIMOPT_SHADOWRES1024 = 2,
  1186.     D3DXSHGPUSIMOPT_SHADOWRES2048 = 3,
  1187.  
  1188.     D3DXSHGPUSIMOPT_HIGHQUALITY = 4,    
  1189.     
  1190.     D3DXSHGPUSIMOPT_FORCE_DWORD = 0x7fffffff
  1191. } D3DXSHGPUSIMOPT;
  1192.  
  1193. // for all properties that are colors the luminance is computed
  1194. // if the simulator is run with a single channel using the following
  1195. // formula:  R * 0.2125 + G * 0.7154 + B * 0.0721
  1196.  
  1197. typedef struct _D3DXSHMATERIAL {
  1198.     D3DCOLORVALUE Diffuse;  // Diffuse albedo of the surface.  (Ignored if object is a Mirror)
  1199.     BOOL          bMirror;  // Must be set to FALSE.  bMirror == TRUE not currently supported
  1200.     BOOL          bSubSurf; // true if the object does subsurface scattering - can't do this and be a mirror
  1201.  
  1202.     // subsurface scattering parameters 
  1203.     FLOAT         RelativeIndexOfRefraction;
  1204.     D3DCOLORVALUE Absorption;
  1205.     D3DCOLORVALUE ReducedScattering;
  1206.  
  1207. } D3DXSHMATERIAL;
  1208.  
  1209. // allocated in D3DXSHPRTCompSplitMeshSC
  1210. // vertices are duplicated into multiple super clusters but
  1211. // only have a valid status in one super cluster (fill in the rest)
  1212.  
  1213. typedef struct _D3DXSHPRTSPLITMESHVERTDATA {
  1214.     UINT  uVertRemap;   // vertex in original mesh this corresponds to
  1215.     UINT  uSubCluster;  // cluster index relative to super cluster
  1216.     UCHAR ucVertStatus; // 1 if vertex has valid data, 0 if it is "fill"
  1217. } D3DXSHPRTSPLITMESHVERTDATA;
  1218.  
  1219. // used in D3DXSHPRTCompSplitMeshSC
  1220. // information for each super cluster that maps into face/vert arrays
  1221.  
  1222. typedef struct _D3DXSHPRTSPLITMESHCLUSTERDATA {
  1223.     UINT uVertStart;     // initial index into remapped vertex array
  1224.     UINT uVertLength;    // number of vertices in this super cluster
  1225.     
  1226.     UINT uFaceStart;     // initial index into face array
  1227.     UINT uFaceLength;    // number of faces in this super cluster
  1228.     
  1229.     UINT uClusterStart;  // initial index into cluster array
  1230.     UINT uClusterLength; // number of clusters in this super cluster
  1231. } D3DXSHPRTSPLITMESHCLUSTERDATA;
  1232.  
  1233. // call back function for simulator
  1234. // return S_OK to keep running the simulator - anything else represents
  1235. // failure and the simulator will abort.
  1236.  
  1237. typedef HRESULT (WINAPI *LPD3DXSHPRTSIMCB)(float fPercentDone,  LPVOID lpUserContext);
  1238.  
  1239. // interfaces for PRT buffers/simulator
  1240.  
  1241. // GUIDs
  1242. // {F1827E47-00A8-49cd-908C-9D11955F8728}
  1243. DEFINE_GUID(IID_ID3DXPRTBuffer, 
  1244. 0xf1827e47, 0xa8, 0x49cd, 0x90, 0x8c, 0x9d, 0x11, 0x95, 0x5f, 0x87, 0x28);
  1245.  
  1246. // {A758D465-FE8D-45ad-9CF0-D01E56266A07}
  1247. DEFINE_GUID(IID_ID3DXPRTCompBuffer, 
  1248. 0xa758d465, 0xfe8d, 0x45ad, 0x9c, 0xf0, 0xd0, 0x1e, 0x56, 0x26, 0x6a, 0x7);
  1249.  
  1250. // {06F57E0A-BD95-43f1-A3DA-791CF6CA297B}
  1251. DEFINE_GUID(IID_ID3DXTextureGutterHelper, 
  1252. 0x6f57e0a, 0xbd95, 0x43f1, 0xa3, 0xda, 0x79, 0x1c, 0xf6, 0xca, 0x29, 0x7b);
  1253.  
  1254. // {C3F4ADBF-E6D2-4b7b-BFE8-9E7208746ADF}
  1255. DEFINE_GUID(IID_ID3DXPRTEngine, 
  1256. 0xc3f4adbf, 0xe6d2, 0x4b7b, 0xbf, 0xe8, 0x9e, 0x72, 0x8, 0x74, 0x6a, 0xdf);
  1257.  
  1258. // interface defenitions
  1259.  
  1260.  
  1261. typedef interface ID3DXTextureGutterHelper ID3DXTextureGutterHelper;
  1262. typedef interface ID3DXTextureGutterHelper *LPD3DXTEXTUREGUTTERHELPER;
  1263.  
  1264. typedef interface ID3DXPRTBuffer ID3DXPRTBuffer;
  1265. typedef interface ID3DXPRTBuffer *LPD3DXPRTBUFFER;
  1266.  
  1267.  
  1268. #undef INTERFACE
  1269. #define INTERFACE ID3DXPRTBuffer
  1270.  
  1271. // Buffer interface - contains "NumSamples" samples
  1272. // each sample in memory is stored as NumCoeffs scalars per channel (1 or 3)
  1273. // Same interface is used for both Vertex and Pixel PRT buffers
  1274.  
  1275. DECLARE_INTERFACE_(ID3DXPRTBuffer, IUnknown)
  1276. {
  1277.     // IUnknown
  1278.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  1279.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  1280.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  1281.  
  1282.     // ID3DXPRTBuffer
  1283.     STDMETHOD_(UINT, GetNumSamples)(THIS) PURE;
  1284.     STDMETHOD_(UINT, GetNumCoeffs)(THIS) PURE;
  1285.     STDMETHOD_(UINT, GetNumChannels)(THIS) PURE;
  1286.  
  1287.     STDMETHOD_(BOOL, IsTexture)(THIS) PURE;
  1288.     STDMETHOD_(UINT, GetWidth)(THIS) PURE;
  1289.     STDMETHOD_(UINT, GetHeight)(THIS) PURE;
  1290.  
  1291.     // changes the number of samples allocated in the buffer
  1292.     STDMETHOD(Resize)(THIS_ UINT NewSize) PURE;
  1293.  
  1294.     // ppData will point to the memory location where sample Start begins
  1295.     // pointer is valid for at least NumSamples samples
  1296.     STDMETHOD(LockBuffer)(THIS_ UINT Start, UINT NumSamples, FLOAT **ppData) PURE;
  1297.     STDMETHOD(UnlockBuffer)(THIS) PURE;
  1298.  
  1299.     // every scalar in buffer is multiplied by Scale
  1300.     STDMETHOD(ScaleBuffer)(THIS_ FLOAT Scale) PURE;
  1301.     
  1302.     // every scalar contains the sum of this and pBuffers values
  1303.     // pBuffer must have the same storage class/dimensions 
  1304.     STDMETHOD(AddBuffer)(THIS_ LPD3DXPRTBUFFER pBuffer) PURE;
  1305.  
  1306.     // GutterHelper (described below) will fill in the gutter
  1307.     // regions of a texture by interpolating "internal" values
  1308.     STDMETHOD(AttachGH)(THIS_ LPD3DXTEXTUREGUTTERHELPER) PURE;
  1309.     STDMETHOD(ReleaseGH)(THIS) PURE;
  1310.     
  1311.     // Evaluates attached gutter helper on the contents of this buffer
  1312.     STDMETHOD(EvalGH)(THIS) PURE;
  1313.  
  1314.     // extracts a given channel into texture pTexture
  1315.     // NumCoefficients starting from StartCoefficient are copied
  1316.     STDMETHOD(ExtractTexture)(THIS_ UINT Channel, UINT StartCoefficient, 
  1317.                               UINT NumCoefficients, LPDIRECT3DTEXTURE9 pTexture) PURE;
  1318.  
  1319.     // extracts NumCoefficients coefficients into mesh - only applicable on single channel
  1320.     // buffers, otherwise just lockbuffer and copy data.  With SHPRT data NumCoefficients 
  1321.     // should be Order^2
  1322.     STDMETHOD(ExtractToMesh)(THIS_ UINT NumCoefficients, D3DDECLUSAGE Usage, UINT UsageIndexStart,
  1323.                              LPD3DXMESH pScene) PURE;
  1324.  
  1325. };
  1326.  
  1327. typedef interface ID3DXPRTCompBuffer ID3DXPRTCompBuffer;
  1328. typedef interface ID3DXPRTCompBuffer *LPD3DXPRTCOMPBUFFER;
  1329.  
  1330. #undef INTERFACE
  1331. #define INTERFACE ID3DXPRTCompBuffer
  1332.  
  1333. // compressed buffers stored a compressed version of a PRTBuffer
  1334.  
  1335. DECLARE_INTERFACE_(ID3DXPRTCompBuffer, IUnknown)
  1336. {
  1337.     // IUnknown
  1338.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  1339.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  1340.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  1341.  
  1342.     // ID3DPRTCompBuffer
  1343.  
  1344.     // NumCoeffs and NumChannels are properties of input buffer
  1345.     STDMETHOD_(UINT, GetNumSamples)(THIS) PURE;
  1346.     STDMETHOD_(UINT, GetNumCoeffs)(THIS) PURE;
  1347.     STDMETHOD_(UINT, GetNumChannels)(THIS) PURE;
  1348.  
  1349.     STDMETHOD_(BOOL, IsTexture)(THIS) PURE;
  1350.     STDMETHOD_(UINT, GetWidth)(THIS) PURE;
  1351.     STDMETHOD_(UINT, GetHeight)(THIS) PURE;
  1352.  
  1353.     // number of clusters, and PCA vectors per-cluster
  1354.     STDMETHOD_(UINT, GetNumClusters)(THIS) PURE;
  1355.     STDMETHOD_(UINT, GetNumPCA)(THIS) PURE;
  1356.  
  1357.     // normalizes PCA weights so that they are between [-1,1]
  1358.     // basis vectors are modified to reflect this
  1359.     STDMETHOD(NormalizeData)(THIS) PURE;
  1360.  
  1361.     // copies basis vectors for cluster "Cluster" into pClusterBasis
  1362.     // (NumPCA+1)*NumCoeffs*NumChannels floats
  1363.     STDMETHOD(ExtractBasis)(THIS_ UINT Cluster, FLOAT *pClusterBasis) PURE;
  1364.     
  1365.     // UINT per sample - which cluster it belongs to
  1366.     STDMETHOD(ExtractClusterIDs)(THIS_ UINT *pClusterIDs) PURE;
  1367.     
  1368.     // copies NumExtract PCA projection coefficients starting at StartPCA
  1369.     // into pPCACoefficients - NumSamples*NumExtract floats copied
  1370.     STDMETHOD(ExtractPCA)(THIS_ UINT StartPCA, UINT NumExtract, FLOAT *pPCACoefficients) PURE;
  1371.  
  1372.     // copies NumPCA projection coefficients starting at StartPCA
  1373.     // into pTexture - should be able to cope with signed formats
  1374.     STDMETHOD(ExtractTexture)(THIS_ UINT StartPCA, UINT NumpPCA, 
  1375.                               LPDIRECT3DTEXTURE9 pTexture) PURE;
  1376.                               
  1377.     // copies NumPCA projection coefficients into mesh pScene
  1378.     // Usage is D3DDECLUSAGE where coefficients are to be stored
  1379.     // UsageIndexStart is starting index
  1380.     STDMETHOD(ExtractToMesh)(THIS_ UINT NumPCA, D3DDECLUSAGE Usage, UINT UsageIndexStart,
  1381.                              LPD3DXMESH pScene) PURE;
  1382. };
  1383.  
  1384.  
  1385. #undef INTERFACE
  1386. #define INTERFACE ID3DXTextureGutterHelper
  1387.  
  1388. // ID3DXTextureGutterHelper will build and manage
  1389. // "gutter" regions in a texture - this will allow for
  1390. // bi-linear interpolation to not have artifacts when rendering
  1391. // It generates a map (in texture space) where each texel
  1392. // is in one of 3 states:
  1393. //   0  Invalid - not used at all
  1394. //   1  Inside triangle
  1395. //   2  Gutter texel
  1396. //   4  represents a gutter texel that will be computed during PRT
  1397. // For each Inside/Gutter texel it stores the face it
  1398. // belongs to and barycentric coordinates for the 1st two
  1399. // vertices of that face.  Gutter vertices are assigned to
  1400. // the closest edge in texture space.
  1401. //
  1402. // When used with PRT this requires a unique parameterization
  1403. // of the model - every texel must correspond to a single point
  1404. // on the surface of the model and vice versa
  1405.  
  1406. DECLARE_INTERFACE_(ID3DXTextureGutterHelper, IUnknown)
  1407. {
  1408.     // IUnknown
  1409.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  1410.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  1411.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  1412.  
  1413.     // ID3DXTextureGutterHelper
  1414.     
  1415.     // dimensions of texture this is bound too
  1416.     STDMETHOD_(UINT, GetWidth)(THIS) PURE;
  1417.     STDMETHOD_(UINT, GetHeight)(THIS) PURE;
  1418.  
  1419.  
  1420.     // Applying gutters recomputes all of the gutter texels of class "2"
  1421.     // based on texels of class "1" or "4"
  1422.     
  1423.     // Applies gutters to a raw float buffer - each texel is NumCoeffs floats
  1424.     // Width and Height must match GutterHelper
  1425.     STDMETHOD(ApplyGuttersFloat)(THIS_ FLOAT *pDataIn, UINT NumCoeffs, UINT Width, UINT Height);
  1426.     
  1427.     // Applies gutters to pTexture
  1428.     // Dimensions must match GutterHelper
  1429.     STDMETHOD(ApplyGuttersTex)(THIS_ LPDIRECT3DTEXTURE9 pTexture);
  1430.     
  1431.     // Applies gutters to a D3DXPRTBuffer
  1432.     // Dimensions must match GutterHelper
  1433.     STDMETHOD(ApplyGuttersPRT)(THIS_ LPD3DXPRTBUFFER pBuffer);
  1434.     
  1435.     // the routines below provide access to the data structures
  1436.     // used by the Apply functions
  1437.  
  1438.     // face map is a UINT per texel that represents the
  1439.     // face of the mesh that texel belongs too - 
  1440.     // only valid if same texel is valid in pGutterData
  1441.     // pFaceData must be allocated by the user
  1442.     STDMETHOD(GetFaceMap)(THIS_ UINT *pFaceData) PURE;
  1443.     
  1444.     // BaryMap is a D3DXVECTOR2 per texel
  1445.     // the 1st two barycentric coordinates for the corresponding
  1446.     // face (3rd weight is always 1-sum of first two)
  1447.     // only valid if same texel is valid in pGutterData
  1448.     // pBaryData must be allocated by the user
  1449.     STDMETHOD(GetBaryMap)(THIS_ D3DXVECTOR2 *pBaryData) PURE;
  1450.     
  1451.     // TexelMap is a D3DXVECTOR2 per texel that
  1452.     // stores the location in pixel coordinates where the
  1453.     // corresponding texel is mapped
  1454.     // pTexelData must be allocated by the user
  1455.     STDMETHOD(GetTexelMap)(THIS_ D3DXVECTOR2 *pTexelData) PURE;
  1456.     
  1457.     // GutterMap is a BYTE per texel
  1458.     // 0/1/2 for Invalid/Internal/Gutter texels
  1459.     // 4 represents a gutter texel that will be computed
  1460.     // during PRT
  1461.     // pGutterData must be allocated by the user
  1462.     STDMETHOD(GetGutterMap)(THIS_ BYTE *pGutterData) PURE;
  1463.     
  1464.     // face map is a UINT per texel that represents the
  1465.     // face of the mesh that texel belongs too - 
  1466.     // only valid if same texel is valid in pGutterData
  1467.     STDMETHOD(SetFaceMap)(THIS_ UINT *pFaceData) PURE;
  1468.     
  1469.     // BaryMap is a D3DXVECTOR2 per texel
  1470.     // the 1st two barycentric coordinates for the corresponding
  1471.     // face (3rd weight is always 1-sum of first two)
  1472.     // only valid if same texel is valid in pGutterData
  1473.     STDMETHOD(SetBaryMap)(THIS_ D3DXVECTOR2 *pBaryData) PURE;
  1474.     
  1475.     // TexelMap is a D3DXVECTOR2 per texel that
  1476.     // stores the location in pixel coordinates where the
  1477.     // corresponding texel is mapped
  1478.     STDMETHOD(SetTexelMap)(THIS_ D3DXVECTOR2 *pTexelData) PURE;
  1479.     
  1480.     // GutterMap is a BYTE per texel
  1481.     // 0/1/2 for Invalid/Internal/Gutter texels
  1482.     // 4 represents a gutter texel that will be computed
  1483.     // during PRT
  1484.     STDMETHOD(SetGutterMap)(THIS_ BYTE *pGutterData) PURE;    
  1485. };
  1486.  
  1487.  
  1488. typedef interface ID3DXPRTEngine ID3DXPRTEngine;
  1489. typedef interface ID3DXPRTEngine *LPD3DXPRTENGINE;
  1490.  
  1491. #undef INTERFACE
  1492. #define INTERFACE ID3DXPRTEngine
  1493.  
  1494. // ID3DXPRTEngine is used to compute a PRT simulation
  1495. // Use the following steps to compute PRT for SH
  1496. // (1) create an interface (which includes a scene)
  1497. // (2) call SetSamplingInfo
  1498. // (3) [optional] Set MeshMaterials/albedo's (required if doing bounces)
  1499. // (4) call ComputeDirectLightingSH
  1500. // (5) [optional] call ComputeBounce
  1501. // repeat step 5 for as many bounces as wanted.
  1502. // if you want to model subsurface scattering you
  1503. // need to call ComputeSS after direct lighting and
  1504. // each bounce.
  1505. // If you want to bake the albedo into the PRT signal, you
  1506. // must call MutliplyAlbedo, otherwise the user has to multiply
  1507. // the albedo themselves.  Not multiplying the albedo allows you
  1508. // to model albedo variation at a finer scale then illumination, and
  1509. // can result in better compression results.
  1510. // Luminance values are computed from RGB values using the following
  1511. // formula:  R * 0.2125 + G * 0.7154 + B * 0.0721
  1512.  
  1513. DECLARE_INTERFACE_(ID3DXPRTEngine, IUnknown)
  1514. {
  1515.     // IUnknown
  1516.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  1517.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  1518.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  1519.  
  1520.     // ID3DXPRTEngine
  1521.     
  1522.     // This sets a material per attribute in the scene mesh and it is
  1523.     // the only way to specify subsurface scattering parameters.  if
  1524.     // bSetAlbedo is FALSE, NumChannels must match the current
  1525.     // configuration of the PRTEngine.  If you intend to change
  1526.     // NumChannels (through some other SetAlbedo function) it must
  1527.     // happen before SetMeshMaterials is called.
  1528.     //
  1529.     // NumChannels 1 implies "grayscale" materials, set this to 3 to enable
  1530.     //  color bleeding effects
  1531.     // bSetAlbedo sets albedo from material if TRUE - which clobbers per texel/vertex
  1532.     //  albedo that might have been set before.  FALSE won't clobber.
  1533.     // fLengthScale is used for subsurface scattering - scene is mapped into a 1mm unit cube
  1534.     //  and scaled by this amount
  1535.     STDMETHOD(SetMeshMaterials)(THIS_ CONST D3DXSHMATERIAL **ppMaterials, UINT NumMeshes, 
  1536.                                 UINT NumChannels, BOOL bSetAlbedo, FLOAT fLengthScale) PURE;
  1537.     
  1538.     // setting albedo per-vertex or per-texel over rides the albedos stored per mesh
  1539.     // but it does not over ride any other settings
  1540.     
  1541.     // sets an albedo to be used per vertex - the albedo is represented as a float
  1542.     // pDataIn input pointer (pointint to albedo of 1st sample)
  1543.     // NumChannels 1 implies "grayscale" materials, set this to 3 to enable
  1544.     //  color bleeding effects
  1545.     // Stride - stride in bytes to get to next samples albedo
  1546.     STDMETHOD(SetPerVertexAlbedo)(THIS_ CONST VOID *pDataIn, UINT NumChannels, UINT Stride) PURE;
  1547.     
  1548.     // represents the albedo per-texel instead of per-vertex (even if per-vertex PRT is used)
  1549.     // pAlbedoTexture - texture that stores the albedo (dimension arbitrary)
  1550.     // NumChannels 1 implies "grayscale" materials, set this to 3 to enable
  1551.     //  color bleeding effects
  1552.     // pGH - optional gutter helper, otherwise one is constructed in computation routines and
  1553.     //  destroyed (if not attached to buffers)
  1554.     STDMETHOD(SetPerTexelAlbedo)(THIS_ LPDIRECT3DTEXTURE9 pAlbedoTexture, 
  1555.                                  UINT NumChannels, 
  1556.                                  LPD3DXTEXTUREGUTTERHELPER pGH) PURE;
  1557.                                  
  1558.     // gets the per-vertex albedo
  1559.     STDMETHOD(GetVertexAlbedo)(THIS_ D3DXCOLOR *pVertColors, UINT NumVerts) PURE;                                 
  1560.                                  
  1561.     // If pixel PRT is being computed normals default to ones that are interpolated
  1562.     // from the vertex normals.  This specifies a texture that stores an object
  1563.     // space normal map instead (must use a texture format that can represent signed values)
  1564.     // pNormalTexture - normal map, must be same dimensions as PRTBuffers, signed                                
  1565.     STDMETHOD(SetPerTexelNormal)(THIS_ LPDIRECT3DTEXTURE9 pNormalTexture) PURE;
  1566.                                  
  1567.     // Copies per-vertex albedo from mesh
  1568.     // pMesh - mesh that represents the scene.  It must have the same
  1569.     //  properties as the mesh used to create the PRTEngine
  1570.     // Usage - D3DDECLUSAGE to extract albedos from
  1571.     // NumChannels 1 implies "grayscale" materials, set this to 3 to enable
  1572.     //  color bleeding effects
  1573.     STDMETHOD(ExtractPerVertexAlbedo)(THIS_ LPD3DXMESH pMesh, 
  1574.                                       D3DDECLUSAGE Usage, 
  1575.                                       UINT NumChannels) PURE;
  1576.  
  1577.     // Resamples the input buffer into the output buffer
  1578.     // can be used to move between per-vertex and per-texel buffers.  This can also be used
  1579.     // to convert single channel buffers to 3-channel buffers and vice-versa.
  1580.     STDMETHOD(ResampleBuffer)(THIS_ LPD3DXPRTBUFFER pBufferIn, LPD3DXPRTBUFFER pBufferOut) PURE;
  1581.     
  1582.     // Returns the scene mesh - including modifications from adaptive spatial sampling
  1583.     // The returned mesh only has positions, normals and texture coordinates (if defined)
  1584.     // pD3DDevice - d3d device that will be used to allocate the mesh
  1585.     // pFaceRemap - each face has a pointer back to the face on the original mesh that it comes from
  1586.     //  if the face hasn't been subdivided this will be an identity mapping
  1587.     // pVertRemap - each vertex contains 3 vertices that this is a linear combination of
  1588.     // pVertWeights - weights for each of above indices (sum to 1.0f)
  1589.     // ppMesh - mesh that will be allocated and filled
  1590.     STDMETHOD(GetAdaptedMesh)(THIS_ LPDIRECT3DDEVICE9 pD3DDevice,UINT *pFaceRemap, UINT *pVertRemap, FLOAT *pfVertWeights, LPD3DXMESH *ppMesh) PURE;
  1591.  
  1592.     // Number of vertices currently allocated (includes new vertices from adaptive sampling)
  1593.     STDMETHOD_(UINT, GetNumVerts)(THIS) PURE;
  1594.     // Number of faces currently allocated (includes new faces)
  1595.     STDMETHOD_(UINT, GetNumFaces)(THIS) PURE;
  1596.  
  1597.     // This will subdivide faces on a mesh so that adaptively simulations can
  1598.     // use a more conservative threshold (it won't miss features.)
  1599.     // MinEdgeLength - minimum edge length that will be generated, if 0.0f a
  1600.     //  reasonable default will be used
  1601.     // MaxSubdiv - maximum level of subdivision, if 0 is specified a default
  1602.     //  value will be used (5)
  1603.     STDMETHOD(RobustMeshRefine)(THIS_ FLOAT MinEdgeLength, UINT MaxSubdiv) PURE;
  1604.  
  1605.     // This sets to sampling information used by the simulator.  Adaptive sampling
  1606.     // parameters are currently ignored.
  1607.     // NumRays - number of rays to shoot per sample
  1608.     // UseSphere - if TRUE uses spherical samples, otherwise samples over
  1609.     //  the hemisphere.  Should only be used with GPU and Vol computations
  1610.     // UseCosine - if TRUE uses a cosine weighting - not used for Vol computations
  1611.     //  or if only the visiblity function is desired
  1612.     // Adaptive - if TRUE adaptive sampling (angular) is used
  1613.     // AdaptiveThresh - threshold used to terminate adaptive angular sampling
  1614.     //  ignored if adaptive sampling is not set
  1615.     STDMETHOD(SetSamplingInfo)(THIS_ UINT NumRays, 
  1616.                                BOOL UseSphere, 
  1617.                                BOOL UseCosine, 
  1618.                                BOOL Adaptive, 
  1619.                                FLOAT AdaptiveThresh) PURE;
  1620.  
  1621.     // Methods that compute the direct lighting contribution for objects
  1622.     // always represente light using spherical harmonics (SH)
  1623.     // the albedo is not multiplied by the signal - it just integrates
  1624.     // incoming light.  If NumChannels is not 1 the vector is replicated
  1625.     //
  1626.     // SHOrder - order of SH to use
  1627.     // pDataOut - PRT buffer that is generated.  Can be single channel
  1628.     STDMETHOD(ComputeDirectLightingSH)(THIS_ UINT SHOrder, 
  1629.                                        LPD3DXPRTBUFFER pDataOut) PURE;
  1630.                                        
  1631.     // Adaptive variant of above function.  This will refine the mesh
  1632.     // generating new vertices/faces to approximate the PRT signal
  1633.     // more faithfully.
  1634.     // SHOrder - order of SH to use
  1635.     // AdaptiveThresh - threshold for adaptive subdivision (in PRT vector error)
  1636.     //  if value is less then 1e-6f, 1e-6f is specified
  1637.     // MinEdgeLength - minimum edge length that will be generated
  1638.     //  if value is too small a fairly conservative model dependent value
  1639.     //  is used
  1640.     // MaxSubdiv - maximum subdivision level, if 0 is specified it 
  1641.     //  will default to 4
  1642.     // pDataOut - PRT buffer that is generated.  Can be single channel.
  1643.     STDMETHOD(ComputeDirectLightingSHAdaptive)(THIS_ UINT SHOrder, 
  1644.                                                FLOAT AdaptiveThresh,
  1645.                                                FLOAT MinEdgeLength,
  1646.                                                UINT MaxSubdiv,
  1647.                                                LPD3DXPRTBUFFER pDataOut) PURE;
  1648.                                        
  1649.     // Function that computes the direct lighting contribution for objects
  1650.     // light is always represented using spherical harmonics (SH)
  1651.     // This is done on the GPU and is much faster then using the CPU.
  1652.     // The albedo is not multiplied by the signal - it just integrates
  1653.     // incoming light.  If NumChannels is not 1 the vector is replicated.
  1654.     // ZBias/ZAngleBias are akin to parameters used with shadow zbuffers.
  1655.     // A reasonable default for both values is 0.005, but the user should
  1656.     // experiment (ZAngleBias can be zero, ZBias should not be.)
  1657.     // Callbacks should not use the Direct3D9Device the simulator is using.
  1658.     // SetSamplingInfo must be called with TRUE for UseSphere and
  1659.     // FALSE for UseCosine before this method is called.
  1660.     //
  1661.     // pD3DDevice - device used to run GPU simulator - must support PS2.0
  1662.     //  and FP render targets
  1663.     // Flags - parameters for the GPU simulator, combination of one or more
  1664.     //  D3DXSHGPUSIMOPT flags.  Only one SHADOWRES setting should be set and
  1665.     //  the defaults is 512
  1666.     // SHOrder - order of SH to use
  1667.     // ZBias - bias in normal direction (for depth test)
  1668.     // ZAngleBias - scaled by one minus cosine of angle with light (offset in depth)
  1669.     // pDataOut - PRT buffer that is filled in.  Can be single channel
  1670.     STDMETHOD(ComputeDirectLightingSHGPU)(THIS_ LPDIRECT3DDEVICE9 pD3DDevice,
  1671.                                           UINT Flags,
  1672.                                           UINT SHOrder,
  1673.                                           FLOAT ZBias,
  1674.                                           FLOAT ZAngleBias,
  1675.                                           LPD3DXPRTBUFFER pDataOut) PURE;
  1676.  
  1677.  
  1678.     // Functions that computes subsurface scattering (using material properties)
  1679.     // Albedo is not multiplied by result.  This only works for per-vertex data
  1680.     // use ResampleBuffer to move per-vertex data into a texture and back.
  1681.     //
  1682.     // pDataIn - input data (previous bounce)
  1683.     // pDataOut - result of subsurface scattering simulation
  1684.     // pDataTotal - [optional] results can be summed into this buffer
  1685.     STDMETHOD(ComputeSS)(THIS_ LPD3DXPRTBUFFER pDataIn, 
  1686.                          LPD3DXPRTBUFFER pDataOut, LPD3DXPRTBUFFER pDataTotal) PURE;
  1687.  
  1688.     // computes a single bounce of inter-reflected light
  1689.     // works for SH based PRT or generic lighting
  1690.     // Albedo is not multiplied by result
  1691.     //
  1692.     // pDataIn - previous bounces data 
  1693.     // pDataOut - PRT buffer that is generated
  1694.     // pDataTotal - [optional] can be used to keep a running sum
  1695.     STDMETHOD(ComputeBounce)(THIS_ LPD3DXPRTBUFFER pDataIn,
  1696.                              LPD3DXPRTBUFFER pDataOut,
  1697.                              LPD3DXPRTBUFFER pDataTotal) PURE;
  1698.  
  1699.     // Adaptive version of above function.
  1700.     //
  1701.     // pDataIn - previous bounces data, can be single channel 
  1702.     // AdaptiveThresh - threshold for adaptive subdivision (in PRT vector error)
  1703.     //  if value is less then 1e-6f, 1e-6f is specified
  1704.     // MinEdgeLength - minimum edge length that will be generated
  1705.     //  if value is too small a fairly conservative model dependent value
  1706.     //  is used
  1707.     // MaxSubdiv - maximum subdivision level, if 0 is specified it 
  1708.     //  will default to 4
  1709.     // pDataOut - PRT buffer that is generated
  1710.     // pDataTotal - [optional] can be used to keep a running sum    
  1711.     STDMETHOD(ComputeBounceAdaptive)(THIS_ LPD3DXPRTBUFFER pDataIn,
  1712.                                      FLOAT AdaptiveThresh,
  1713.                                      FLOAT MinEdgeLength,
  1714.                                      UINT MaxSubdiv,
  1715.                                      LPD3DXPRTBUFFER pDataOut,
  1716.                                      LPD3DXPRTBUFFER pDataTotal) PURE;
  1717.  
  1718.     // Computes projection of distant SH radiance into a local SH radiance
  1719.     // function.  This models how direct lighting is attenuated by the 
  1720.     // scene and is a form of "neighborhood transfer."  The result is
  1721.     // a linear operator (matrix) at every sample point, if you multiply
  1722.     // this matrix by the distant SH lighting coefficients you get an
  1723.     // approximation of the local incident radiance function from
  1724.     // direct lighting.  These resulting lighting coefficients can
  1725.     // than be projected into another basis or used with any rendering
  1726.     // technique that uses spherical harmonics as input.
  1727.     // SetSamplingInfo must be called with TRUE for UseSphere and
  1728.     // FALSE for UseCosine before this method is called.  
  1729.     // Generates SHOrderIn*SHOrderIn*SHOrderOut*SHOrderOut scalars 
  1730.     // per channel at each sample location.
  1731.     //
  1732.     // SHOrderIn  - Order of the SH representation of distant lighting
  1733.     // SHOrderOut - Order of the SH representation of local lighting
  1734.     // NumVolSamples  - Number of sample locations
  1735.     // pSampleLocs    - position of sample locations
  1736.     // pDataOut       - PRT Buffer that will store output results    
  1737.     STDMETHOD(ComputeVolumeSamplesDirectSH)(THIS_ UINT SHOrderIn, 
  1738.                                             UINT SHOrderOut, 
  1739.                                             UINT NumVolSamples,
  1740.                                             CONST D3DXVECTOR3 *pSampleLocs,
  1741.                                             LPD3DXPRTBUFFER pDataOut) PURE;
  1742.                                     
  1743.     // At each sample location computes a linear operator (matrix) that maps
  1744.     // the representation of source radiance (NumCoeffs in pSurfDataIn)
  1745.     // into a local incident radiance function approximated with spherical 
  1746.     // harmonics.  For example if a light map data is specified in pSurfDataIn
  1747.     // the result is an SH representation of the flow of light at each sample
  1748.     // point.  If PRT data for an outdoor scene is used, each sample point
  1749.     // contains a matrix that models how distant lighting bounces of the objects
  1750.     // in the scene and arrives at the given sample point.  Combined with
  1751.     // ComputeVolumeSamplesDirectSH this gives the complete representation for
  1752.     // how light arrives at each sample point parameterized by distant lighting.
  1753.     // SetSamplingInfo must be called with TRUE for UseSphere and
  1754.     // FALSE for UseCosine before this method is called.    
  1755.     // Generates pSurfDataIn->NumCoeffs()*SHOrder*SHOrder scalars
  1756.     // per channel at each sample location.
  1757.     //
  1758.     // pSurfDataIn    - previous bounce data
  1759.     // SHOrder        - order of SH to generate projection with
  1760.     // NumVolSamples  - Number of sample locations
  1761.     // pSampleLocs    - position of sample locations
  1762.     // pDataOut       - PRT Buffer that will store output results
  1763.     STDMETHOD(ComputeVolumeSamples)(THIS_ LPD3DXPRTBUFFER pSurfDataIn, 
  1764.                                     UINT SHOrder, 
  1765.                                     UINT NumVolSamples,
  1766.                                     CONST D3DXVECTOR3 *pSampleLocs,
  1767.                                     LPD3DXPRTBUFFER pDataOut) PURE;
  1768.     // Frees temporary data structures that can be created for subsurface scattering
  1769.     // this data is freed when the PRTComputeEngine is freed and is lazily created
  1770.     STDMETHOD(FreeSSData)(THIS) PURE;
  1771.     
  1772.     // Frees temporary data structures that can be created for bounce simulations
  1773.     // this data is freed when the PRTComputeEngine is freed and is lazily created
  1774.     STDMETHOD(FreeBounceData)(THIS) PURE;
  1775.  
  1776.     // This computes the convolution coefficients relative to the per sample normals
  1777.     // that minimize error in a least squares sense with respect to the input PRT
  1778.     // data set.  These coefficients can be used with skinned/transformed normals to
  1779.     // model global effects with dynamic objects.  Shading normals can optionaly be
  1780.     // solved for - these normals (along with the convolution coefficients) can more
  1781.     // accurately represent the PRT signal.
  1782.     //
  1783.     // pDataIn  - SH PRT dataset that is input
  1784.     // SHOrder  - Order of SH to compute conv coefficients for 
  1785.     // pNormOut - Optional array of vectors (passed in) that will be filled with
  1786.     //             "shading normals", convolution coefficients are optimized for
  1787.     //             these normals.  This array must be the same size as the number of
  1788.     //             samples in pDataIn
  1789.     // pDataOut - Output buffer (SHOrder convolution coefficients per channel per sample)
  1790.     STDMETHOD(ComputeConvCoeffs)(THIS_ LPD3DXPRTBUFFER pDataIn,
  1791.                                  UINT SHOrder,
  1792.                                  D3DXVECTOR3 *pNormOut,
  1793.                                  LPD3DXPRTBUFFER pDataOut) PURE;
  1794.  
  1795.     // scales all the samples associated with a given sub mesh
  1796.     // can be useful when using subsurface scattering
  1797.     // fScale - value to scale each vector in submesh by
  1798.     STDMETHOD(ScaleMeshChunk)(THIS_ UINT uMeshChunk, FLOAT fScale, LPD3DXPRTBUFFER pDataOut) PURE;
  1799.     
  1800.     // mutliplies each PRT vector by the albedo - can be used if you want to have the albedo
  1801.     // burned into the dataset, often better not to do this.  If this is not done the user
  1802.     // must mutliply the albedo themselves when rendering - just multiply the albedo times
  1803.     // the result of the PRT dot product.
  1804.     // If pDataOut is a texture simulation result and there is an albedo texture it
  1805.     // must be represented at the same resolution as the simulation buffer.  You can use
  1806.     // LoadSurfaceFromSurface and set a new albedo texture if this is an issue - but must
  1807.     // be careful about how the gutters are handled.
  1808.     //
  1809.     // pDataOut - dataset that will get albedo pushed into it
  1810.     STDMETHOD(MultiplyAlbedo)(THIS_ LPD3DXPRTBUFFER pDataOut) PURE;
  1811.     
  1812.     // Sets a pointer to an optional call back function that reports back to the
  1813.     // user percentage done and gives them the option of quitting
  1814.     // pCB - pointer to call back function, return S_OK for the simulation
  1815.     //  to continue
  1816.     // Frequency - 1/Frequency is roughly the number of times the call back
  1817.     //  will be invoked
  1818.     // lpUserContext - will be passed back to the users call back
  1819.     STDMETHOD(SetCallBack)(THIS_ LPD3DXSHPRTSIMCB pCB, FLOAT Frequency,  LPVOID lpUserContext) PURE;
  1820. };
  1821.  
  1822.  
  1823. // API functions for creating interfaces
  1824.  
  1825. #ifdef __cplusplus
  1826. extern "C" {
  1827. #endif //__cplusplus
  1828.  
  1829. //============================================================================
  1830. //
  1831. //  D3DXCreatePRTBuffer:
  1832. //  --------------------
  1833. //  Generates a PRT Buffer that can be compressed or filled by a simulator
  1834. //  This function should be used to create per-vertex or volume buffers.
  1835. //  When buffers are created all values are initialized to zero.
  1836. //
  1837. //  Parameters:
  1838. //    NumSamples
  1839. //      Number of sample locations represented
  1840. //    NumCoeffs
  1841. //      Number of coefficients per sample location (order^2 for SH)
  1842. //    NumChannels
  1843. //      Number of color channels to represent (1 or 3)
  1844. //    ppBuffer
  1845. //      Buffer that will be allocated
  1846. //
  1847. //============================================================================
  1848.  
  1849. HRESULT WINAPI 
  1850.     D3DXCreatePRTBuffer( 
  1851.         UINT NumSamples,
  1852.         UINT NumCoeffs,
  1853.         UINT NumChannels,
  1854.         LPD3DXPRTBUFFER* ppBuffer);
  1855.  
  1856. //============================================================================
  1857. //
  1858. //  D3DXCreatePRTBufferTex:
  1859. //  --------------------
  1860. //  Generates a PRT Buffer that can be compressed or filled by a simulator
  1861. //  This function should be used to create per-pixel buffers.
  1862. //  When buffers are created all values are initialized to zero.
  1863. //
  1864. //  Parameters:
  1865. //    Width
  1866. //      Width of texture
  1867. //    Height
  1868. //      Height of texture
  1869. //    NumCoeffs
  1870. //      Number of coefficients per sample location (order^2 for SH)
  1871. //    NumChannels
  1872. //      Number of color channels to represent (1 or 3)
  1873. //    ppBuffer
  1874. //      Buffer that will be allocated
  1875. //
  1876. //============================================================================
  1877.  
  1878. HRESULT WINAPI
  1879.     D3DXCreatePRTBufferTex( 
  1880.         UINT Width,
  1881.         UINT Height,
  1882.         UINT NumCoeffs,
  1883.         UINT NumChannels,
  1884.         LPD3DXPRTBUFFER* ppBuffer);
  1885.  
  1886. //============================================================================
  1887. //
  1888. //  D3DXLoadPRTBufferFromFile:
  1889. //  --------------------
  1890. //  Loads a PRT buffer that has been saved to disk.
  1891. //
  1892. //  Parameters:
  1893. //    pFilename
  1894. //      Name of the file to load
  1895. //    ppBuffer
  1896. //      Buffer that will be allocated
  1897. //
  1898. //============================================================================
  1899.  
  1900. HRESULT WINAPI
  1901.     D3DXLoadPRTBufferFromFileA(
  1902.         LPCSTR pFilename, 
  1903.         LPD3DXPRTBUFFER*       ppBuffer);
  1904.         
  1905. HRESULT WINAPI
  1906.     D3DXLoadPRTBufferFromFileW(
  1907.         LPCWSTR pFilename, 
  1908.         LPD3DXPRTBUFFER*       ppBuffer);
  1909.  
  1910. #ifdef UNICODE
  1911. #define D3DXLoadPRTBufferFromFile D3DXLoadPRTBufferFromFileW
  1912. #else
  1913. #define D3DXLoadPRTBufferFromFile D3DXLoadPRTBufferFromFileA
  1914. #endif
  1915.  
  1916.  
  1917. //============================================================================
  1918. //
  1919. //  D3DXSavePRTBufferToFile:
  1920. //  --------------------
  1921. //  Saves a PRTBuffer to disk.
  1922. //
  1923. //  Parameters:
  1924. //    pFilename
  1925. //      Name of the file to save
  1926. //    pBuffer
  1927. //      Buffer that will be saved
  1928. //
  1929. //============================================================================
  1930.  
  1931. HRESULT WINAPI
  1932.     D3DXSavePRTBufferToFileA(
  1933.         LPCSTR pFileName,
  1934.         LPD3DXPRTBUFFER pBuffer);
  1935.         
  1936. HRESULT WINAPI
  1937.     D3DXSavePRTBufferToFileW(
  1938.         LPCWSTR pFileName,
  1939.         LPD3DXPRTBUFFER pBuffer);
  1940.  
  1941. #ifdef UNICODE
  1942. #define D3DXSavePRTBufferToFile D3DXSavePRTBufferToFileW
  1943. #else
  1944. #define D3DXSavePRTBufferToFile D3DXSavePRTBufferToFileA
  1945. #endif                
  1946.  
  1947.  
  1948. //============================================================================
  1949. //
  1950. //  D3DXLoadPRTCompBufferFromFile:
  1951. //  --------------------
  1952. //  Loads a PRTComp buffer that has been saved to disk.
  1953. //
  1954. //  Parameters:
  1955. //    pFilename
  1956. //      Name of the file to load
  1957. //    ppBuffer
  1958. //      Buffer that will be allocated
  1959. //
  1960. //============================================================================
  1961.  
  1962. HRESULT WINAPI
  1963.     D3DXLoadPRTCompBufferFromFileA(
  1964.         LPCSTR pFilename, 
  1965.         LPD3DXPRTCOMPBUFFER*       ppBuffer);
  1966.         
  1967. HRESULT WINAPI
  1968.     D3DXLoadPRTCompBufferFromFileW(
  1969.         LPCWSTR pFilename, 
  1970.         LPD3DXPRTCOMPBUFFER*       ppBuffer);
  1971.  
  1972. #ifdef UNICODE
  1973. #define D3DXLoadPRTCompBufferFromFile D3DXLoadPRTCompBufferFromFileW
  1974. #else
  1975. #define D3DXLoadPRTCompBufferFromFile D3DXLoadPRTCompBufferFromFileA
  1976. #endif
  1977.  
  1978. //============================================================================
  1979. //
  1980. //  D3DXSavePRTCompBufferToFile:
  1981. //  --------------------
  1982. //  Saves a PRTCompBuffer to disk.
  1983. //
  1984. //  Parameters:
  1985. //    pFilename
  1986. //      Name of the file to save
  1987. //    pBuffer
  1988. //      Buffer that will be saved
  1989. //
  1990. //============================================================================
  1991.  
  1992. HRESULT WINAPI
  1993.     D3DXSavePRTCompBufferToFileA(
  1994.         LPCSTR pFileName,
  1995.         LPD3DXPRTCOMPBUFFER pBuffer);
  1996.         
  1997. HRESULT WINAPI
  1998.     D3DXSavePRTCompBufferToFileW(
  1999.         LPCWSTR pFileName,
  2000.         LPD3DXPRTCOMPBUFFER pBuffer);
  2001.  
  2002. #ifdef UNICODE
  2003. #define D3DXSavePRTCompBufferToFile D3DXSavePRTCompBufferToFileW
  2004. #else
  2005. #define D3DXSavePRTCompBufferToFile D3DXSavePRTCompBufferToFileA
  2006. #endif 
  2007.  
  2008. //============================================================================
  2009. //
  2010. //  D3DXCreatePRTCompBuffer:
  2011. //  --------------------
  2012. //  Compresses a PRT buffer (vertex or texel)
  2013. //
  2014. //  Parameters:
  2015. //    D3DXSHCOMPRESSQUALITYTYPE
  2016. //      Quality of compression - low is faster (computes PCA per voronoi cluster)
  2017. //      high is slower but better quality (clusters based on distance to affine subspace)
  2018. //    NumClusters
  2019. //      Number of clusters to compute
  2020. //    NumPCA
  2021. //      Number of basis vectors to compute
  2022. //    ppBufferIn
  2023. //      Buffer that will be compressed
  2024. //    ppBufferOut
  2025. //      Compressed buffer that will be created
  2026. //
  2027. //============================================================================
  2028.  
  2029.  
  2030. HRESULT WINAPI
  2031.     D3DXCreatePRTCompBuffer(
  2032.         D3DXSHCOMPRESSQUALITYTYPE Quality,
  2033.         UINT NumClusters, 
  2034.         UINT NumPCA,
  2035.         LPD3DXPRTBUFFER  pBufferIn,
  2036.         LPD3DXPRTCOMPBUFFER *ppBufferOut
  2037.     );
  2038.  
  2039. //============================================================================
  2040. //
  2041. //  D3DXCreateTextureGutterHelper:
  2042. //  --------------------
  2043. //  Generates a "GutterHelper" for a given set of meshes and texture
  2044. //  resolution
  2045. //
  2046. //  Parameters:
  2047. //    Width
  2048. //      Width of texture
  2049. //    Height
  2050. //      Height of texture
  2051. //    pMesh
  2052. //      Mesh that represents the scene
  2053. //    GutterSize
  2054. //      Number of texels to over rasterize in texture space
  2055. //      this should be at least 1.0
  2056. //    ppBuffer
  2057. //      GutterHelper that will be created
  2058. //
  2059. //============================================================================
  2060.  
  2061.  
  2062. HRESULT WINAPI 
  2063.     D3DXCreateTextureGutterHelper( 
  2064.         UINT Width,
  2065.         UINT Height,
  2066.         LPD3DXMESH pMesh, 
  2067.         FLOAT GutterSize,
  2068.         LPD3DXTEXTUREGUTTERHELPER* ppBuffer);
  2069.  
  2070.  
  2071. //============================================================================
  2072. //
  2073. //  D3DXCreatePRTEngine:
  2074. //  --------------------
  2075. //  Computes a PRTEngine which can efficiently generate PRT simulations
  2076. //  of a scene
  2077. //
  2078. //  Parameters:
  2079. //    pMesh
  2080. //      Mesh that represents the scene - must have an AttributeTable
  2081. //      where vertices are in a unique attribute.
  2082. //    ExtractUVs
  2083. //      Set this to true if textures are going to be used for albedos
  2084. //      or to store PRT vectors
  2085. //    pBlockerMesh
  2086. //      Optional mesh that just blocks the scene
  2087. //    ppEngine
  2088. //      PRTEngine that will be created
  2089. //
  2090. //============================================================================
  2091.  
  2092.  
  2093. HRESULT WINAPI 
  2094.     D3DXCreatePRTEngine( 
  2095.         LPD3DXMESH pMesh, 
  2096.         BOOL ExtractUVs,
  2097.         LPD3DXMESH pBlockerMesh, 
  2098.         LPD3DXPRTENGINE* ppEngine);
  2099.  
  2100. //============================================================================
  2101. //
  2102. //  D3DXConcatenateMeshes:
  2103. //  --------------------
  2104. //  Concatenates a group of meshes into one common mesh.  This can optionaly transform
  2105. //  each sub mesh or its texture coordinates.  If no DECL is given it will
  2106. //  generate a union of all of the DECL's of the sub meshes, promoting channels
  2107. //  and types if neccesary.  It will create an AttributeTable if possible, one can
  2108. //  call OptimizeMesh with attribute sort and compacting enabled to ensure this.
  2109. //
  2110. //  Parameters:
  2111. //    ppMeshes
  2112. //      Array of pointers to meshes that can store PRT vectors
  2113. //    NumMeshes
  2114. //      Number of meshes
  2115. //    Options
  2116. //      Passed through to D3DXCreateMesh
  2117. //    pGeomXForms
  2118. //      [optional] Each sub mesh is transformed by the corresponding
  2119. //      matrix if this array is supplied
  2120. //    pTextureXForms
  2121. //      [optional] UV coordinates for each sub mesh are transformed
  2122. //      by corresponding matrix if supplied
  2123. //    pDecl
  2124. //      [optional] Only information in this DECL is used when merging
  2125. //      data
  2126. //    pD3DDevice
  2127. //      D3D device that is used to create the new mesh
  2128. //    ppMeshOut
  2129. //      Mesh that will be created
  2130. //
  2131. //============================================================================
  2132.  
  2133.  
  2134. HRESULT WINAPI 
  2135.     D3DXConcatenateMeshes(
  2136.         LPD3DXMESH *ppMeshes, 
  2137.         UINT NumMeshes, 
  2138.         DWORD Options, 
  2139.         CONST D3DXMATRIX *pGeomXForms, 
  2140.         CONST D3DXMATRIX *pTextureXForms, 
  2141.         CONST D3DVERTEXELEMENT9 *pDecl,
  2142.         LPDIRECT3DDEVICE9 pD3DDevice, 
  2143.         LPD3DXMESH *ppMeshOut);
  2144.  
  2145. //============================================================================
  2146. //
  2147. //  D3DXSHPRTCompSuperCluster:
  2148. //  --------------------------
  2149. //  Used with compressed results of D3DXSHPRTSimulation.
  2150. //  Generates "super clusters" - groups of clusters that can be drawn in
  2151. //  the same draw call.  A greedy algorithm that minimizes overdraw is used
  2152. //  to group the clusters.
  2153. //
  2154. //  Parameters:
  2155. //   pClusterIDs
  2156. //      NumVerts cluster ID's (extracted from a compressed buffer)
  2157. //   pScene
  2158. //      Mesh that represents composite scene passed to the simulator
  2159. //   MaxNumClusters
  2160. //      Maximum number of clusters allocated per super cluster
  2161. //   NumClusters
  2162. //      Number of clusters computed in the simulator
  2163. //   pSuperClusterIDs
  2164. //      Array of length NumClusters, contains index of super cluster
  2165. //      that corresponding cluster was assigned to
  2166. //   pNumSuperClusters
  2167. //      Returns the number of super clusters allocated
  2168. //      
  2169. //============================================================================
  2170.  
  2171. HRESULT WINAPI 
  2172.     D3DXSHPRTCompSuperCluster(
  2173.         UINT *pClusterIDs, 
  2174.         LPD3DXMESH pScene, 
  2175.         UINT MaxNumClusters, 
  2176.         UINT NumClusters,
  2177.         UINT *pSuperClusterIDs, 
  2178.         UINT *pNumSuperClusters);
  2179.  
  2180. //============================================================================
  2181. //
  2182. //  D3DXSHPRTCompSplitMeshSC:
  2183. //  -------------------------
  2184. //  Used with compressed results of the vertex version of the PRT simulator.
  2185. //  After D3DXSHRTCompSuperCluster has been called this function can be used
  2186. //  to split the mesh into a group of faces/vertices per super cluster.
  2187. //  Each super cluster contains all of the faces that contain any vertex
  2188. //  classified in one of its clusters.  All of the vertices connected to this
  2189. //  set of faces are also included with the returned array ppVertStatus 
  2190. //  indicating whether or not the vertex belongs to the supercluster.
  2191. //
  2192. //  Parameters:
  2193. //   pClusterIDs
  2194. //      NumVerts cluster ID's (extracted from a compressed buffer)
  2195. //   NumVertices
  2196. //      Number of vertices in original mesh
  2197. //   NumClusters
  2198. //      Number of clusters (input parameter to compression)
  2199. //   pSuperClusterIDs
  2200. //      Array of size NumClusters that will contain super cluster ID's (from
  2201. //      D3DXSHCompSuerCluster)
  2202. //   NumSuperClusters
  2203. //      Number of superclusters allocated in D3DXSHCompSuerCluster
  2204. //   pInputIB
  2205. //      Raw index buffer for mesh - format depends on bInputIBIs32Bit
  2206. //   InputIBIs32Bit
  2207. //      Indicates whether the input index buffer is 32-bit (otherwise 16-bit
  2208. //      is assumed)
  2209. //   NumFaces
  2210. //      Number of faces in the original mesh (pInputIB is 3 times this length)
  2211. //   ppIBData
  2212. //      LPD3DXBUFFER holds raw index buffer that will contain the resulting split faces.  
  2213. //      Format determined by bIBIs32Bit.  Allocated by function
  2214. //   pIBDataLength
  2215. //      Length of ppIBData, assigned in function
  2216. //   OutputIBIs32Bit
  2217. //      Indicates whether the output index buffer is to be 32-bit (otherwise 
  2218. //      16-bit is assumed)
  2219. //   ppFaceRemap
  2220. //      LPD3DXBUFFER mapping of each face in ppIBData to original faces.  Length is
  2221. //      *pIBDataLength/3.  Optional paramter, allocated in function
  2222. //   ppVertData
  2223. //      LPD3DXBUFFER contains new vertex data structure.  Size of pVertDataLength
  2224. //   pVertDataLength
  2225. //      Number of new vertices in split mesh.  Assigned in function
  2226. //   pSCClusterList
  2227. //      Array of length NumClusters which pSCData indexes into (Cluster* fields)
  2228. //      for each SC, contains clusters sorted by super cluster
  2229. //   pSCData
  2230. //      Structure per super cluster - contains indices into ppIBData,
  2231. //      pSCClusterList and ppVertData
  2232. //
  2233. //============================================================================
  2234.  
  2235. HRESULT WINAPI 
  2236.     D3DXSHPRTCompSplitMeshSC(
  2237.         UINT *pClusterIDs, 
  2238.         UINT NumVertices, 
  2239.         UINT NumClusters, 
  2240.         UINT *pSuperClusterIDs, 
  2241.         UINT NumSuperClusters,
  2242.         LPVOID pInputIB, 
  2243.         BOOL InputIBIs32Bit, 
  2244.         UINT NumFaces,
  2245.         LPD3DXBUFFER *ppIBData, 
  2246.         UINT *pIBDataLength, 
  2247.         BOOL OutputIBIs32Bit, 
  2248.         LPD3DXBUFFER *ppFaceRemap, 
  2249.         LPD3DXBUFFER *ppVertData, 
  2250.         UINT *pVertDataLength, 
  2251.         UINT *pSCClusterList,
  2252.         D3DXSHPRTSPLITMESHCLUSTERDATA *pSCData);
  2253.         
  2254.         
  2255. #ifdef __cplusplus
  2256. }
  2257. #endif //__cplusplus
  2258.  
  2259. //////////////////////////////////////////////////////////////////////////////
  2260. //
  2261. //  Definitions of .X file templates used by mesh load/save functions 
  2262. //    that are not RM standard
  2263. //
  2264. //////////////////////////////////////////////////////////////////////////////
  2265.  
  2266. // {3CF169CE-FF7C-44ab-93C0-F78F62D172E2}
  2267. DEFINE_GUID(DXFILEOBJ_XSkinMeshHeader,
  2268. 0x3cf169ce, 0xff7c, 0x44ab, 0x93, 0xc0, 0xf7, 0x8f, 0x62, 0xd1, 0x72, 0xe2);
  2269.  
  2270. // {B8D65549-D7C9-4995-89CF-53A9A8B031E3}
  2271. DEFINE_GUID(DXFILEOBJ_VertexDuplicationIndices, 
  2272. 0xb8d65549, 0xd7c9, 0x4995, 0x89, 0xcf, 0x53, 0xa9, 0xa8, 0xb0, 0x31, 0xe3);
  2273.  
  2274. // {A64C844A-E282-4756-8B80-250CDE04398C}
  2275. DEFINE_GUID(DXFILEOBJ_FaceAdjacency, 
  2276. 0xa64c844a, 0xe282, 0x4756, 0x8b, 0x80, 0x25, 0xc, 0xde, 0x4, 0x39, 0x8c);
  2277.  
  2278. // {6F0D123B-BAD2-4167-A0D0-80224F25FABB}
  2279. DEFINE_GUID(DXFILEOBJ_SkinWeights, 
  2280. 0x6f0d123b, 0xbad2, 0x4167, 0xa0, 0xd0, 0x80, 0x22, 0x4f, 0x25, 0xfa, 0xbb);
  2281.  
  2282. // {A3EB5D44-FC22-429d-9AFB-3221CB9719A6}
  2283. DEFINE_GUID(DXFILEOBJ_Patch, 
  2284. 0xa3eb5d44, 0xfc22, 0x429d, 0x9a, 0xfb, 0x32, 0x21, 0xcb, 0x97, 0x19, 0xa6);
  2285.  
  2286. // {D02C95CC-EDBA-4305-9B5D-1820D7704BBF}
  2287. DEFINE_GUID(DXFILEOBJ_PatchMesh, 
  2288. 0xd02c95cc, 0xedba, 0x4305, 0x9b, 0x5d, 0x18, 0x20, 0xd7, 0x70, 0x4b, 0xbf);
  2289.  
  2290. // {B9EC94E1-B9A6-4251-BA18-94893F02C0EA}
  2291. DEFINE_GUID(DXFILEOBJ_PatchMesh9, 
  2292. 0xb9ec94e1, 0xb9a6, 0x4251, 0xba, 0x18, 0x94, 0x89, 0x3f, 0x2, 0xc0, 0xea);
  2293.  
  2294. // {B6C3E656-EC8B-4b92-9B62-681659522947}
  2295. DEFINE_GUID(DXFILEOBJ_PMInfo, 
  2296. 0xb6c3e656, 0xec8b, 0x4b92, 0x9b, 0x62, 0x68, 0x16, 0x59, 0x52, 0x29, 0x47);
  2297.  
  2298. // {917E0427-C61E-4a14-9C64-AFE65F9E9844}
  2299. DEFINE_GUID(DXFILEOBJ_PMAttributeRange, 
  2300. 0x917e0427, 0xc61e, 0x4a14, 0x9c, 0x64, 0xaf, 0xe6, 0x5f, 0x9e, 0x98, 0x44);
  2301.  
  2302. // {574CCC14-F0B3-4333-822D-93E8A8A08E4C}
  2303. DEFINE_GUID(DXFILEOBJ_PMVSplitRecord,
  2304. 0x574ccc14, 0xf0b3, 0x4333, 0x82, 0x2d, 0x93, 0xe8, 0xa8, 0xa0, 0x8e, 0x4c);
  2305.  
  2306. // {B6E70A0E-8EF9-4e83-94AD-ECC8B0C04897}
  2307. DEFINE_GUID(DXFILEOBJ_FVFData, 
  2308. 0xb6e70a0e, 0x8ef9, 0x4e83, 0x94, 0xad, 0xec, 0xc8, 0xb0, 0xc0, 0x48, 0x97);
  2309.  
  2310. // {F752461C-1E23-48f6-B9F8-8350850F336F}
  2311. DEFINE_GUID(DXFILEOBJ_VertexElement, 
  2312. 0xf752461c, 0x1e23, 0x48f6, 0xb9, 0xf8, 0x83, 0x50, 0x85, 0xf, 0x33, 0x6f);
  2313.  
  2314. // {BF22E553-292C-4781-9FEA-62BD554BDD93}
  2315. DEFINE_GUID(DXFILEOBJ_DeclData, 
  2316. 0xbf22e553, 0x292c, 0x4781, 0x9f, 0xea, 0x62, 0xbd, 0x55, 0x4b, 0xdd, 0x93);
  2317.  
  2318. // {F1CFE2B3-0DE3-4e28-AFA1-155A750A282D}
  2319. DEFINE_GUID(DXFILEOBJ_EffectFloats, 
  2320. 0xf1cfe2b3, 0xde3, 0x4e28, 0xaf, 0xa1, 0x15, 0x5a, 0x75, 0xa, 0x28, 0x2d);
  2321.  
  2322. // {D55B097E-BDB6-4c52-B03D-6051C89D0E42}
  2323. DEFINE_GUID(DXFILEOBJ_EffectString, 
  2324. 0xd55b097e, 0xbdb6, 0x4c52, 0xb0, 0x3d, 0x60, 0x51, 0xc8, 0x9d, 0xe, 0x42);
  2325.  
  2326. // {622C0ED0-956E-4da9-908A-2AF94F3CE716}
  2327. DEFINE_GUID(DXFILEOBJ_EffectDWord, 
  2328. 0x622c0ed0, 0x956e, 0x4da9, 0x90, 0x8a, 0x2a, 0xf9, 0x4f, 0x3c, 0xe7, 0x16);
  2329.  
  2330. // {3014B9A0-62F5-478c-9B86-E4AC9F4E418B}
  2331. DEFINE_GUID(DXFILEOBJ_EffectParamFloats, 
  2332. 0x3014b9a0, 0x62f5, 0x478c, 0x9b, 0x86, 0xe4, 0xac, 0x9f, 0x4e, 0x41, 0x8b);
  2333.  
  2334. // {1DBC4C88-94C1-46ee-9076-2C28818C9481}
  2335. DEFINE_GUID(DXFILEOBJ_EffectParamString, 
  2336. 0x1dbc4c88, 0x94c1, 0x46ee, 0x90, 0x76, 0x2c, 0x28, 0x81, 0x8c, 0x94, 0x81);
  2337.  
  2338. // {E13963BC-AE51-4c5d-B00F-CFA3A9D97CE5}
  2339. DEFINE_GUID(DXFILEOBJ_EffectParamDWord,
  2340. 0xe13963bc, 0xae51, 0x4c5d, 0xb0, 0xf, 0xcf, 0xa3, 0xa9, 0xd9, 0x7c, 0xe5);
  2341.  
  2342. // {E331F7E4-0559-4cc2-8E99-1CEC1657928F}
  2343. DEFINE_GUID(DXFILEOBJ_EffectInstance, 
  2344. 0xe331f7e4, 0x559, 0x4cc2, 0x8e, 0x99, 0x1c, 0xec, 0x16, 0x57, 0x92, 0x8f);
  2345.  
  2346. // {9E415A43-7BA6-4a73-8743-B73D47E88476}
  2347. DEFINE_GUID(DXFILEOBJ_AnimTicksPerSecond, 
  2348. 0x9e415a43, 0x7ba6, 0x4a73, 0x87, 0x43, 0xb7, 0x3d, 0x47, 0xe8, 0x84, 0x76);
  2349.  
  2350. // {7F9B00B3-F125-4890-876E-1CFFBF697C4D}
  2351. DEFINE_GUID(DXFILEOBJ_CompressedAnimationSet, 
  2352. 0x7f9b00b3, 0xf125, 0x4890, 0x87, 0x6e, 0x1c, 0x42, 0xbf, 0x69, 0x7c, 0x4d);
  2353.  
  2354. #pragma pack(push, 1)
  2355. typedef struct _XFILECOMPRESSEDANIMATIONSET
  2356. {
  2357.     DWORD CompressedBlockSize;
  2358.     FLOAT TicksPerSec;
  2359.     DWORD PlaybackType;
  2360.     DWORD BufferLength;
  2361. } XFILECOMPRESSEDANIMATIONSET;
  2362. #pragma pack(pop)
  2363.  
  2364. #define XSKINEXP_TEMPLATES \
  2365.         "xof 0303txt 0032\
  2366.         template XSkinMeshHeader \
  2367.         { \
  2368.             <3CF169CE-FF7C-44ab-93C0-F78F62D172E2> \
  2369.             WORD nMaxSkinWeightsPerVertex; \
  2370.             WORD nMaxSkinWeightsPerFace; \
  2371.             WORD nBones; \
  2372.         } \
  2373.         template VertexDuplicationIndices \
  2374.         { \
  2375.             <B8D65549-D7C9-4995-89CF-53A9A8B031E3> \
  2376.             DWORD nIndices; \
  2377.             DWORD nOriginalVertices; \
  2378.             array DWORD indices[nIndices]; \
  2379.         } \
  2380.         template FaceAdjacency \
  2381.         { \
  2382.             <A64C844A-E282-4756-8B80-250CDE04398C> \
  2383.             DWORD nIndices; \
  2384.             array DWORD indices[nIndices]; \
  2385.         } \
  2386.         template SkinWeights \
  2387.         { \
  2388.             <6F0D123B-BAD2-4167-A0D0-80224F25FABB> \
  2389.             STRING transformNodeName; \
  2390.             DWORD nWeights; \
  2391.             array DWORD vertexIndices[nWeights]; \
  2392.             array float weights[nWeights]; \
  2393.             Matrix4x4 matrixOffset; \
  2394.         } \
  2395.         template Patch \
  2396.         { \
  2397.             <A3EB5D44-FC22-429D-9AFB-3221CB9719A6> \
  2398.             DWORD nControlIndices; \
  2399.             array DWORD controlIndices[nControlIndices]; \
  2400.         } \
  2401.         template PatchMesh \
  2402.         { \
  2403.             <D02C95CC-EDBA-4305-9B5D-1820D7704BBF> \
  2404.             DWORD nVertices; \
  2405.             array Vector vertices[nVertices]; \
  2406.             DWORD nPatches; \
  2407.             array Patch patches[nPatches]; \
  2408.             [ ... ] \
  2409.         } \
  2410.         template PatchMesh9 \
  2411.         { \
  2412.             <B9EC94E1-B9A6-4251-BA18-94893F02C0EA> \
  2413.             DWORD Type; \
  2414.             DWORD Degree; \
  2415.             DWORD Basis; \
  2416.             DWORD nVertices; \
  2417.             array Vector vertices[nVertices]; \
  2418.             DWORD nPatches; \
  2419.             array Patch patches[nPatches]; \
  2420.             [ ... ] \
  2421.         } " \
  2422.         "template EffectFloats \
  2423.         { \
  2424.             <F1CFE2B3-0DE3-4e28-AFA1-155A750A282D> \
  2425.             DWORD nFloats; \
  2426.             array float Floats[nFloats]; \
  2427.         } \
  2428.         template EffectString \
  2429.         { \
  2430.             <D55B097E-BDB6-4c52-B03D-6051C89D0E42> \
  2431.             STRING Value; \
  2432.         } \
  2433.         template EffectDWord \
  2434.         { \
  2435.             <622C0ED0-956E-4da9-908A-2AF94F3CE716> \
  2436.             DWORD Value; \
  2437.         } " \
  2438.         "template EffectParamFloats \
  2439.         { \
  2440.             <3014B9A0-62F5-478c-9B86-E4AC9F4E418B> \
  2441.             STRING ParamName; \
  2442.             DWORD nFloats; \
  2443.             array float Floats[nFloats]; \
  2444.         } " \
  2445.         "template EffectParamString \
  2446.         { \
  2447.             <1DBC4C88-94C1-46ee-9076-2C28818C9481> \
  2448.             STRING ParamName; \
  2449.             STRING Value; \
  2450.         } \
  2451.         template EffectParamDWord \
  2452.         { \
  2453.             <E13963BC-AE51-4c5d-B00F-CFA3A9D97CE5> \
  2454.             STRING ParamName; \
  2455.             DWORD Value; \
  2456.         } \
  2457.         template EffectInstance \
  2458.         { \
  2459.             <E331F7E4-0559-4cc2-8E99-1CEC1657928F> \
  2460.             STRING EffectFilename; \
  2461.             [ ... ] \
  2462.         } " \
  2463.         "template AnimTicksPerSecond \
  2464.         { \
  2465.             <9E415A43-7BA6-4a73-8743-B73D47E88476> \
  2466.             DWORD AnimTicksPerSecond; \
  2467.         } \
  2468.         template CompressedAnimationSet \
  2469.         { \
  2470.             <7F9B00B3-F125-4890-876E-1C42BF697C4D> \
  2471.             DWORD CompressedBlockSize; \
  2472.             FLOAT TicksPerSec; \
  2473.             DWORD PlaybackType; \
  2474.             DWORD BufferLength; \
  2475.             array DWORD CompressedData[BufferLength]; \
  2476.         } "
  2477.  
  2478. #define XEXTENSIONS_TEMPLATES \
  2479.         "xof 0303txt 0032\
  2480.         template FVFData \
  2481.         { \
  2482.             <B6E70A0E-8EF9-4e83-94AD-ECC8B0C04897> \
  2483.             DWORD dwFVF; \
  2484.             DWORD nDWords; \
  2485.             array DWORD data[nDWords]; \
  2486.         } \
  2487.         template VertexElement \
  2488.         { \
  2489.             <F752461C-1E23-48f6-B9F8-8350850F336F> \
  2490.             DWORD Type; \
  2491.             DWORD Method; \
  2492.             DWORD Usage; \
  2493.             DWORD UsageIndex; \
  2494.         } \
  2495.         template DeclData \
  2496.         { \
  2497.             <BF22E553-292C-4781-9FEA-62BD554BDD93> \
  2498.             DWORD nElements; \
  2499.             array VertexElement Elements[nElements]; \
  2500.             DWORD nDWords; \
  2501.             array DWORD data[nDWords]; \
  2502.         } \
  2503.         template PMAttributeRange \
  2504.         { \
  2505.             <917E0427-C61E-4a14-9C64-AFE65F9E9844> \
  2506.             DWORD iFaceOffset; \
  2507.             DWORD nFacesMin; \
  2508.             DWORD nFacesMax; \
  2509.             DWORD iVertexOffset; \
  2510.             DWORD nVerticesMin; \
  2511.             DWORD nVerticesMax; \
  2512.         } \
  2513.         template PMVSplitRecord \
  2514.         { \
  2515.             <574CCC14-F0B3-4333-822D-93E8A8A08E4C> \
  2516.             DWORD iFaceCLW; \
  2517.             DWORD iVlrOffset; \
  2518.             DWORD iCode; \
  2519.         } \
  2520.         template PMInfo \
  2521.         { \
  2522.             <B6C3E656-EC8B-4b92-9B62-681659522947> \
  2523.             DWORD nAttributes; \
  2524.             array PMAttributeRange attributeRanges[nAttributes]; \
  2525.             DWORD nMaxValence; \
  2526.             DWORD nMinLogicalVertices; \
  2527.             DWORD nMaxLogicalVertices; \
  2528.             DWORD nVSplits; \
  2529.             array PMVSplitRecord splitRecords[nVSplits]; \
  2530.             DWORD nAttributeMispredicts; \
  2531.             array DWORD attributeMispredicts[nAttributeMispredicts]; \
  2532.         } "
  2533.         
  2534. #endif //__D3DX9MESH_H__
  2535.  
  2536.  
  2537.